Metodo XML DOM removeChild()
❮ Oggetto Elemento
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e rimuove un nodo figlio nel primo elemento <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 =
"Removed
node: " + x.nodeName;
}
Produzione:
Node removed: book
Definizione e utilizzo
Il metodo removeChild() rimuove un nodo figlio.
Questa funzione restituisce il nodo rimosso in caso di successo o NULL in caso di errore.
Sintassi
elementNode.removeChild(node)
Parameter | Description |
---|---|
node | Required. Specifies the child node to remove |
Dimostrazioni fai-da-te
❮ Oggetto Elemento