...

View Full Version : Node emptier



Choopernickel
02-10-2004, 11:03 PM
From a different challenge involving time-sensitive text, I came up with this little goodie.


function clearNode (node) {
node.normalize();
while (node.childNodes.length > 0) {
node.removeChild(node.firstChild);
}
return node;
}

I'd like to make this a method of the Node prototype, but I haven't figured out *quite* how to do it yet. Comments? Improvements?

liorean
02-10-2004, 11:49 PM
Didn't normalise have the irritating property that it crashes some version of ie? I think I remember something like htat happening. Anyway, the Node object is only exhibited by Opera and Mozilla for the moment, so you'de not going to find a way to do that. Make it a global function instead.

brothercake
02-21-2004, 04:34 AM
Are you looking to remove useless whitespace text nodes from a node tree? Cos Alex Vincent wrote a nifty method for that - http://www.codingforums.com/showthread.php?s=&threadid=7028

Except don't let it run in mac/ie5, because in that browser HTML structures become unstable when stripped of whitespace.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum