Metode XML DOM removeAttributeNS()
Definisi dan Penggunaan
removeAttributeNS()
Metode untuk menghapus atribut yang ditentukan oleh namespace dan nama.
Sintaks
elementNode.removeAttributeNS(ns,name)
Parameter | Deskripsi |
---|---|
ns | Wajib. Tentukan namespace atribut yang akan dihapus. |
name | Wajib. Tentukan nama atribut yang akan dihapus. |
Contoh
Berikut kode ini akan mengambil "books_ns.xml" ke xmlDoc dan menghapus atribut "lang" dari elemen <title> pertama:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books_ns.xml", true); xhttp.send(); function myFunction(xml) { var xmlDoc = xml.responseXML; var x = xmlDoc.getElementsByTagName("title")[0]; var ns = "https://www.codew3c.com/meishi/"; document.getElementById("demo").innerHTML = "Attribute Found: " + x.hasAttributeNS(ns, \"lang\"); x.removeAttributeNS(ns, "lang"); document.getElementById("demo").innerHTML += "<br>Attribute Ditemukan: " + x.hasAttributeNS(ns, "lang"); }