XML DOM removeAttributeNS()เมธอด
❮ วัตถุธาตุ
ตัวอย่าง
โค้ดย่อยต่อไปนี้โหลด " books_ns.xml " ลงใน xmlDoc และลบแอตทริบิวต์ "lang" ออกจากองค์ประกอบ <title> แรก:
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 =
"Attribute
Found: " + x.hasAttributeNS(ns, "lang");
x.removeAttributeNS(ns, "lang");
document.getElementById("demo").innerHTML +=
"<br>Attribute
Found: " + x.hasAttributeNS(ns, "lang");
}
เอาท์พุท:
Attribute Found: true
Attribute Found: false
ความหมายและการใช้งาน
เมธอด removeAttributeNS() จะลบแอตทริบิวต์ที่ระบุโดยเนมสเปซและชื่อ
ไวยากรณ์
elementNode.removeAttributeNS(ns,name)
Parameter | Description |
---|---|
ns | Required. Specifies the namespace of the attribute to remove |
name | Required. Specifies the name attribute to remove |
❮ วัตถุธาตุ