XML DOM removeAttribute()メソッド
❮要素オブジェクト
例
次のコードフラグメントは、「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');
}
出力:
cooking
null
定義と使用法
removeAttribute()メソッドは、指定された属性を削除します。
属性のデフォルト値がDTDで定義されている場合、新しい属性がデフォルト値ですぐに表示されます
構文
elementNode.removeAttribute(name)
Parameter | Description |
---|---|
name | Required. Specifies the attribute to remove |
❮要素オブジェクト