[thelist] DOM - removeNode() problems

Jeff Howden jeff at jeffhowden.com
Mon Aug 4 21:43:55 CDT 2003


tom,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Tom Dell'Aringa
>
> http://www.pixelmech.com/test/DOM_errors.html
>
> I'm displaying form errors using the DOM instead of
> alerts. I'm able to write out the errors using
> appendChild() no problem in both IE and Gecko/Moz. The
> problem I run into is with removeNode().
>
> [snip]
>
> This works fine up to a point. In IE and Moz, the nodes
> appear to be removed. IE will even continue after that,
> not throwing an error. But the new error messages are
> never written out again. If I check for the DIV object
> I am using to appendChild() the errors to, it returns
> as an object (true). This is odd.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

no it's not.  the removeNode() method acts upon the object you're calling it
on.  in other words, if you're calling the removeNode() method on the <div>
you originally appended the node to, then that node will be removed.  once
removed, it's no longer available for later.

you've got three choices that are effectively equivalent.

first, and simplest, you can set the innerHTML of your error <div> to an
empty string.

second, you can return an array of all the child nodes in the error <div>,
loop over that array, and remove each child node independently using the
removeNode() method, calling it on each child node.

or third, you can return an array of all the child nodes in the error <div>,
loop over that array, and remove each child node independently using the
removeChild() method, calling it on the parent node.

the second and third incur roughly the same amount of coding and performance
hit.

the first is by far the best performing and the least amount of code, but
may not pass your purist-dom test.

.jeff

------------------------------------------------------
Jeff Howden - Web Application Specialist
Resume - http://jeffhowden.com/about/resume/
Code Library - http://evolt.jeffhowden.com/jeff/code/




More information about the thelist mailing list