Just a quick post

I've been working on a pretty simple bit of code where one "row" of information is removed and added to a different table of information.  Pretty simple stuff.

However, I ran into a issue with IE7 (go figure, right?).  When using the "removeChild()" function, IE was not always removing the element specified.  I debugged my code to no end, and couldn't find any issues.

Now I'm not sure if this is an actual bug, or an error in implementation on my part, but I ran across a post that seems to indicate that the best way to handle removeChild() in IE is to recursively remove all of the element's children, ending with the element itself (most other browsers don't seem to care, and just remove what you ask for!).  

So really, I'm saying anything new, but just getting Google a bit more information to work with to other poor slobs looking for this answer.

Here's where I found the solution:

And here's the recursive function:

function removeChildSafe(el) {    //before deleting el, recursively delete all of its children.    while(el.childNodes.length > 0) {        removeChildSafe(el.childNodes[el.childNodes.length-1]);    }    el.parentNode.removeChild(el);}

 

Share this: