how to loop over the child divs of a div and get the ids of the child divs?
Try this
var childDivs = document.getElementById('test').getElementsByTagName('div');
for( i=0; i< childDivs.length; i++ )
{
var childDiv = childDivs[i];
}
Here's the solution if somebody still looks for it
function getDivChildren(containerId, elementsId) {
var div = document.getElementById(containerId),
subDiv = div.getElementsByTagName('div'),
myArray = [];
for(var i = 0; i < subDiv.length; i++) {
var elem = subDiv[i];
if(elem.id.indexOf(elementsId) === 0) {
myArray.push(elem.id);
}
}
return myArray;
}
console.log(getDivChildren('test', 'test-'));
You can loop through inner divs using jQuery .each() function. The following example does this and for each inner div it gets the id attribute.
$('#test').find('div').each(function(){
var innerDivId = $(this).attr('id');
});