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]

引数

  • indexunsigned long の値です。

返値

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 GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
item

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報