I’m dynamically adding nodes and need to remove them. The removing is causing problems.
This is my code
for(var x = 0; x < Node.childNodes.length; x++)
{
alert(“Removing ” + Node.childNodes[x].nodeName);
Node.removeChild(Node.childNodes[x]);
}
The funny thing is it only removes 4 nodes and I have counted and checked the source code there are more than 4 ndoes. The fact that some are left behind is causing me trouble. Can anyone tell me what is wrong with this code?
The nodes appear to be added and interpreted correctly (node.appendChild(newNode), basic stuff)
But they are not all being removed correctly. Can anyone help me diagnose the problem?
P.S.
I noticed that the first removal extracts a #text node from the parent node. Could that be signifigant? The #text is an empty node with no text actually inside of it seems to just have an empty space to cover the “innerText” of the parent tag.
Thanks for your help