Document: getElementsByName() メソッド
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.
構文
js
getElementsByName(name)
引数
name
-
探している要素の
name
属性の値です。
返値
生きた NodeList
コレクション、つまり文書内で同じ name
を持った新しい要素が追加されたり削除されたりすると自動的に更新されるものです。
例
html
<!doctype html>
<html lang="ja">
<head>
<title>document.getElementsByName の使用例</title>
</head>
<body>
<input type="hidden" name="up" />
<input type="hidden" name="down" />
</body>
</html>
js
const up_names = document.getElementsByName("up");
console.log(up_names[0].tagName); // "INPUT" と表示
メモ
仕様書
Specification |
---|
HTML # dom-document-getelementsbyname-dev |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getElementsByName |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- See implementation notes.
- Has more compatibility info.
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.
関連情報
document.getElementById()
: 固有のid
を持つ要素への参照を返すdocument.getElementsByTagName()
: 同じタグ名の要素への参照を返すdocument.querySelector()
:'div.myclass'
のような CSS セレクターによって要素への参照を返す