Element: getAttributeNode() メソッド
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
この要素の指定された属性を、Attr
ノードとして返します。
構文
js
getAttributeNode(attrName)
引数
attrName
は属性の名前を表す文字列です。
返値
指定の属性の Attr
ノードです。
例
js
// html: <div id="top" />
let t = document.getElementById("top");
let idAttr = t.getAttributeNode("id");
alert(idAttr.value === "top");
メモ
HTML 文書としてフラグが立てられた DOM 内の HTML 要素に対して呼び出された場合、getAttributeNode
は処理前に引数を小文字にします。
Attr
ノードは Node
を継承していますが、文書ツリーの一部と考えることはできません。一般の Node
属性、例えば parentNode、 previousSibling、nextSibling などは Attr
ノードでは null
になります。しかしながら、 ownerElement
プロパティではこの属性が属している要素を取得することができます。
要素の属性の値を取得するためには、通常 getAttributeNode
の代わりに getAttribute が使用されます。
仕様書
Specification |
---|
DOM # dom-element-getattributenode |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getAttributeNode |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.