the singularity of being and nothingness
removeChild() and IE7
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);
}
Print article | This entry was posted by existdissolve on January 27, 2009 at 6:31 am, and is filed under Microsoft. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about -1916 years ago
Maybe something to tell the jQuery guys? I’ve also found some bugs in jQuery (I think). For example, when using the :last selector, it doesn’t seem to recurse to all elements below. Found out when I created a dropdown…