XML DOM removeChild() Method
❮ Element Object
Example
The following code fragment loads "books.xml" into xmlDoc and removes a child node in the first <book> element:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var y =
xmlDoc.getElementsByTagName("book")[0];
var x =
xmlDoc.documentElement.removeChild(y);
document.getElementById("demo").innerHTML =
"Removed
node: " + x.nodeName;
}
Output:
Node removed: book
Try it Yourself »
Definition and Usage
The removeChild() method removes a child node.
This function returns the removed node on success, or NULL on failure.
Syntax
elementNode.removeChild(node)
Parameter | Description |
---|---|
node | Required. Specifies the child node to remove |
Try-It-Yourself Demos
removeChild() - Remove the last child node from a nodelist
❮ Element Object