XML DOM removeChild() Metode
Objek Elemen
Contoh
Fragmen kode berikut memuat " books.xml " ke dalam xmlDoc dan menghapus simpul anak di elemen <book> pertama:
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;
}
Keluaran:
Node removed: book
Definisi dan Penggunaan
Metode removeChild() menghapus simpul anak.
Fungsi ini mengembalikan node yang dihapus saat berhasil, atau NULL saat gagal.
Sintaksis
elementNode.removeChild(node)
Parameter | Description |
---|---|
node | Required. Specifies the child node to remove |
Demo Coba Sendiri
Objek Elemen