[Javascript] How to destroy an element?

Matt Warden mwarden at gmail.com
Fri Aug 18 14:16:26 CDT 2006


On 8/18/06, diego nunes <dnunes at gmail.com> wrote:
> On 8/18/06, Peter Lauri <lists at dwsasia.com> wrote:
> > Can I destroy an element?
>
>   I wrote a little function to remove elements that can receive any
> iteratable collection os elementos (NodeList, Array, etc) and remove
> them all from the document. It can also, of course, receive a single
> dom reference to a element.
> function rEs(tO) { var i, n; if (!tO) { return false; }
>   if (!tO.nodeName) { if (tO.length) for (n=tO.length; n--;) rEs(tO[n]); }
>   else tO.parentNode.removeChild(tO);
> }

Have you done any work in determining if this causes a memory leak if
tO has child nodes? I whipped up this function a while back to
recursively remove all children and meant to do some comparison
testing, but never got around to it:

http://mwarden.f2o.org/sandbox/removechildrenrecursively.js

-- 
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the Javascript mailing list