Metode XML DOM hasAttributeNS()
Objek Elemen
Contoh
Fragmen kode berikut memuat " books_ns.xml " ke dalam xmlDoc dan memeriksa apakah elemen <title> pertama memiliki atribut namespace dan nama yang ditentukan:
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.w3schools.com/children/";
document.getElementById("demo").innerHTML =
x.hasAttributeNS(ns,"lang");
}
Keluaran:
true
Definisi dan Penggunaan
Metode hasAttributeNS() mengembalikan TRUE jika node elemen saat ini memiliki atribut yang ditentukan oleh namespace dan nama, dan FALSE sebaliknya.
Sintaksis
hasAttributeNS(ns,name)
Parameter | Description |
---|---|
ns | Required. Specifies the namespace of the attribute to find |
name | Required. Specifies the name of the attribute to find |
Objek Elemen