HTMLSelectElement.item()
HTMLSelectElement.item() メソッドは、選択肢のリスト内で引数で渡された位置にある HTMLOptionElement に対応する Element を返します。存在しない場合は null を返します。
JavaScript では、ブラケット構文に unsigned long の値を入れた selectElt[index] の形が、selectElt.namedItem(index) と同等になります。
構文
js
var item = collection.item(index);
var item = 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
css
// Returns the HTMLOptionElement representing #o2
elem1 = document.forms[0]['myFormControl'][1];
仕様書
| Specification |
|---|
| HTML Standard # dom-select-item-dev |
ブラウザーの互換性
BCD tables only load in the browser
関連情報
- 実装先の
HTMLSelectElement