HTMLSelectElement: item() メソッド
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 Standard # dom-select-item-dev |
ブラウザーの互換性
BCD tables only load in the browser
関連情報
- 実装先の
HTMLSelectElement