Tech Info - W3C DOM-2 removeChild Method: "Removes the specified thing (an element/node/object) from the referenced node.
Syntax
oldthing = node.removeChild(thing)
Related Stuff
appendChild method
Parameters
Name Description Notes
node the node to be removed
Examples
// get a reference to an existing object
obj = document.getElementById('one');
// empty this object of its children
nodelist = obj.childNodes;
// now loop and remove them all
c = nodelist.length; // needed because changes dynamically
for(i = 0; i < c; i++)
{
this_node = nodelist[0]; // reference changes dynamically
removed_node = obj.removeChild(this_node);
}
// alternate method
while(obj.hasChildNodes() == true)
{
obj.removeChild(obj.childNodes[0]);
}
}
The code fragment above shows two versions of a loop which empties a node of all its child nodes."
0 Comments:
Post a Comment
<< Home