XML DOM removeChild()Methods
Element object
Definition and Usage
The removeChild() method removes child nodes.
If the function succeeds, it returns the deleted node; if it fails, it returns NULL.
Syntax
elementNode.removeChild(node)
| Parameter | Description |
|---|---|
| node | Required. Specifies the child node to be removed. |
Example
The following code snippet usesloadXMLDoc()put "books.xml" Load into xmlDoc, and delete the child nodes of the first <book> element:
Example
xmlDoc=loadXMLDoc("books.xml");
y=xmlDoc.getElementsByTagName("book")[0];
x=xmlDoc.documentElement.removeChild(y);
document.write("Removed node: " + x.nodeName);
y=xmlDoc.getElementsByTagName("book")[0];
x=xmlDoc.documentElement.removeChild(y);
document.write("Removed node: " + x.nodeName);
Output:
Node removed: book
Try it Yourself »
Try Demos
removeChild() - Removes the last child node from the node list.
Element objectother extensions