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.
Try this
var childDivs = document.getElementById('test').getElementsByTagName('div'); for( i=0; i< childDivs.length; i++ ) { var childDiv = childDivs[i]; }