HTML DOM getAttribute()メソッド
例
リンクの target 属性値を取得する:
document.getElementsByTagName("a")[0].getAttribute("target");
出力結果:
_blank
試してみる »
定義と使い方
getAttribute() メソッドは、名前を使用して属性の値を取得します。
ヒント:属性を返したい場合は、 getAttributeNodeメソッドを使用してください。
ブラウザサポート
![]()
![]()
![]()
![]()
![]()
すべての主要ブラウザが getAttribute() メソッドをサポートしています。
構文
element.getAttribute(attributename)
パラメータ
| パラメータ | 型 | 説明 |
|---|---|---|
| attributename | String | 必須。取得したい属性の値。 |
戻り値
| 型 | 説明 |
|---|---|
| String | 指定した属性の値 |
技術詳細
| DOM バージョン | Core Level 1 Element Object |
|---|
その他の拡張
要素オブジェクト