Método removeChild() del DOM XML

Definición y uso

removeChild() Método para eliminar un nodo hijo.

Al éxito, esta función devuelve el nodo eliminado, y al fracasar devuelve NULL

Sintaxis

elementNode.removeChild(node)
Parámetros Descripción
node Requerido. Especifica el elemento hijo que se debe eliminar.

Ejemplo

Ejemplo 1

El siguiente código carga "books.xml" en xmlDoc y elimina los elementos hijos del primer <book>:

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 =
    "Nodo eliminado: " + x.nodeName;
{}

Prueba personalmente

Ejemplo 2

Eliminar el último elemento hijo de la lista de nodos:

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 len = xmlDoc.getElementsByTagName('book').length;
    var y = xmlDoc.getElementsByTagName("book")[len-1];
    var x = xmlDoc.documentElement.removeChild(y);
    document.getElementById("demo").innerHTML =
    "Nodo eliminado: " + x.nodeName;
{}

Prueba personalmente