I have a div with id test
and through the foreach loop I am creating some inner divs inside the test div. So it becomes like this.
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-'));