FREE Web Template Download
HTML CSS JAVASCRIPT SQL PHP BOOTSTRAP JQUERY ANGULARJS TUTORIALS REFERENCES EXAMPLES Blog
 

XML DOM removeChild() Method


Element Object Reference 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 (xhttp.readyState == 4 && xhttp.status == 200) {
       myFunction(xhttp);
   }
};
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 Reference Element Object