There doesn't seem to be any mechanism to "clear" a node of all
it's children (not that its necessary very often, but I have come
across situations where I'd like to clear a node of all it's
children before appending other nodes). I've come up with two
possibilities:
function removeAllChildNodes(node) {
if (node && node.hasChildNodes && node.removeChild) {
while (node.hasChildNodes()) {
node.removeChild(node.firstChild);
}
}
} // removeAllChildNodes()
or
function removeAllChildNodes(node) {
if (node && node.parentNode && node.parentNode.replaceChild
&& node.cloneNode) {
node.parentNode.replaceChild(node.cloneNode(false) ,
node);
}
} // removeAllChildNodes()
Which do you like better and why? Is there an easier method or
way of clearing the children of a node that I'm missing?
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available
at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html