HTML DOM removeAttributeNode()メソッド
❮要素オブジェクト例
<h1>要素からクラス属性ノードを削除します。
var elmnt = document.getElementsByTagName("H1")[0]; // Get the first <h1> element in the document
var attr = elmnt.getAttributeNode("class"); // Get the class attribute node from <h1>
elmnt.removeAttributeNode(attr); // Remove the class attribute node from <h1>
定義と使用法
removeAttributeNode()メソッドは、指定された属性を要素から削除し、削除された属性を AttrNodeオブジェクトとして返します。
このメソッドとremoveAttribute()メソッドの違いは、 removeAttribute()メソッドが指定された名前の属性を削除するのに対し、このメソッドは指定されたAttrオブジェクトを削除することです。結果は同じになります。また、removeAttribute()メソッドには戻り値がありませんが、このメソッドは削除された属性をAttrオブジェクトとして返します。
ヒント: getAttributeNode()メソッドを使用して、要素の属性ノードを返します。
ヒント: setAttributeNode()メソッドを使用して、要素に属性ノードを追加します。
ブラウザのサポート
Method | |||||
---|---|---|---|---|---|
removeAttributeNode() | Yes | Yes | Yes | Yes | Yes |
構文
element.removeAttributeNode(attributenode)
パラメータ値
Parameter | Type | Description |
---|---|---|
attributenode | Attr object | Required. The attribute node you want to remove |
技術的な詳細
戻り値: | 削除された属性ノードを表すAttrオブジェクト |
---|---|
DOMバージョン | コアレベル1要素オブジェクト |
その他の例
例
<a>要素からhref属性ノードを削除します。
var elmnt = document.getElementById("myAnchor"); // Get the <a> element with id="myAnchor"
var attr = elmnt.getAttributeNode("href"); // Get the href attribute node from <a>
elmnt.removeAttributeNode(attr); // Remove the href attribute node from <a>
関連ページ
HTMLチュートリアル:HTML属性
HTML DOMリファレンス:HTMLDOM属性オブジェクト
HTML DOMリファレンス:removeAttribute()メソッド
HTML DOMリファレンス:getAttributeNode()メソッド
HTML DOMリファレンス:setAttributeNode()メソッド
❮要素オブジェクト