Thread: Node emptier
View Single Post
Old 02-10-2004, 10:03 PM   PM User | #1
Choopernickel
Regular Coder

 
Join Date: Apr 2003
Location: Atlanta, GA
Posts: 487
Thanks: 0
Thanked 0 Times in 0 Posts
Choopernickel is an unknown quantity at this point
Node emptier

From a different challenge involving time-sensitive text, I came up with this little goodie.

Code:
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?
Choopernickel is offline   Reply With Quote