I am trying to make following piece of code to work for each child node once. THe function is also deleting the node as per logic, for more than one child node it never seems to traverse to each child node.
//Deleting from child node
var target =document.getElementById(element.name).childNodes[0];
if(target.hasChildNodes())
{
var children = new Array();
children = target.childNodes;
for(child in children)
{
if(children[child].tagName == 'DIV'){
//target.removeChild[child];
var deleteChild = document.getElementById(target.childNodes[child].id);
deleteChild.parentNode.removeChild(deleteChild);
}
}
}
In a special case i have 4 "Div" as child, this only remove two DIV and not all. I assume as the length is also changing constantly, hence it's not able to get to all children.
Is this correct way of traversal, am i missing something obvious?