XML DOM removeAttributeNS() メソッド
定義と使用法
removeAttributeNS()
命名空間と名前で指定された属性を削除するメソッドです。
構文
elementNode.removeAttributeNS(ns,name)
パラメータ | 説明 |
---|---|
ns | 必須。削除する属性の命名空間を指定します。 |
name | 必須。削除する属性の名前を指定します。 |
例
以下のコードは、"books_ns.xml"をxmlDocにロードし、最初の<title>要素から"lang"属性を削除します:
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 = "属性已找到: " + x.hasAttributeNS(ns, "lang"); x.removeAttributeNS(ns, "lang"); document.getElementById("demo").innerHTML += "<br>属性が見つかりました: " + x.hasAttributeNS(ns, "lang"); }