このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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 ⁨2015年7月⁩.

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

ブラウザーの互換性

関連情報