XML DOM removeAttribute() メソッド
定義と使用法
指定された属性を削除します。
メソッド
属性のデフォルト値が DTD で定義されている場合、デフォルト値を持つ新しい属性がすぐに表示されます。
文法
elementNode.removeAttribute(name)
引数 | 説明 |
---|---|
name | 必須。削除する属性を指定します。 |
例
以下のコードは "books.xml" を xmlDoc に読み込み、すべての <book> 要素から "category" 属性を削除します:
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 x = xmlDoc.getElementsByTagName("book"); document.getElementById("demo").innerHTML = x[0].getAttribute('category') + "<br>"; x[0].removeAttribute('category'); document.getElementById("demo").innerHTML +=; x[0].getAttribute('category'); }