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 removeAllChildN odes(node) {
if (node && node.hasChildNo des && node.removeChil d) {
while (node.hasChildN odes()) {
node.removeChil d(node.firstChi ld);
}
}
} // removeAllChildN odes()
or
function removeAllChildN odes(node) {
if (node && node.parentNode && node.parentNode .replaceChild
&& node.cloneNode) {
node.parentNode .replaceChild(n ode.cloneNode(f alse),
node);
}
} // removeAllChildN odes()
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*****@agrico reunited.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