XML DOM removeChild () method
Definition and Usage
removeChild () method to remove child nodes.
If successful, the function returns the node is removed, if it fails to return NULL.
grammar
elementNode.removeChild(node)
参数 | 描述 |
---|---|
node | 必需。规定要删除的子节点。 |
Examples
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and remove the first <book> element child nodes:
Examples
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"
Try Demos
removeChild () - Remove the last child node from the list
Element object