XML DOM removeChild() Method
Node Object
Example
The following code fragment loads "books.xml" into xmlDoc and removes the first child node in the first <book> node:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
��� if (xhttp.readyState == 4 && xhttp.status == 200) {
������� myFunction(xhttp);
��� }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var root =
xmlDoc.documentElement;
var currNode = root.childNodes[1];
removedNode = currNode.removeChild(currNode.childNodes[1]);
document.getElementById("demo").innerHTML =
"Removed
node: " + removedNode.nodeName;
}
Output:
Removed node: title
Try it yourself »
Definition and Usage
The removeChild() method removes a specified child node from the current node.
Tip: The removed child node can be inserted later into any element in the same document. Use the insertBefore() or appendChild() method to insert it later into the same document, or use the adoptNode() or importNode() method to insert the removed node into another document.
Browser Support
The removeChild() method is supported in all major browsers.
Syntax
nodeObject.removeChild(child)
Parameters
Parameter | Type | Description |
---|---|---|
child | Node object | Required. The node to remove |
Return Value
Type | Description |
---|---|
Node object | Returns the removed node as a Node object |
Technical Details
DOM Version | Core Level 1 Node Object. Modified in DOM Level 3 |
---|
Node Object