HTMLSelectElement: item() メソッド
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.
HTMLSelectElement.item()
メソッドは、選択肢のリスト内で引数で渡された位置にある HTMLOptionElement
に対応する Element
を返します。存在しない場合は null
を返します。
JavaScript では、ブラケット構文に unsigned long
の値を入れた selectElt[index]
の形で、selectElt.namedItem(index)
と同等になります。
構文
js
item(index)
// or collection[index]
引数
index
はunsigned long
の値です。
返値
item
はHTMLOptionElement
です。
例
HTML
html
<form>
<select id="myFormControl">
<option id="o1">Opt 1</option>
<option id="o2">Opt 2</option>
</select>
</form>
JavaScript
js
// Returns the HTMLOptionElement representing #o2
elem1 = document.forms[0]["myFormControl"][1];
仕様書
Specification |
---|
HTML # dom-select-item-dev |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
item |
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.
関連情報
- 実装先の
HTMLSelectElement