Clearing a DOM Sub-Tree

© 2011, Martin Rinehart

Given that you have node_ref, a reference to a DOM node, this simple bit of JavaScript will clear all its children, except in MSIE: node_ref.innerHTML = '';.

The innerHTML is not a W3C standard, but it is a de facto standard. It often works in MSIE, too. To be certain, use:

    while ( node_ref.hasChildren ) {
        node_ref.removeChild( node_ref.firstChild );

Feedback: MartinRinehart at gmail dot com

# # #