HTMLSelectElement.item()

The HTMLSelectElement.item() method returns the Element corresponding to the HTMLOptionElement whose position in the options list corresponds to the index given in parameter, or null if there are none.

In JavaScript, using the array bracket syntax with an unsigned long, like selectElt[idx] is equivalent to selectElt.namedItem(idx).

Syntax

JavaScript
var item = collection.item[idx];
var item = collection[idx];

Parameters

  • idx is an unsigned long.

Return value

Examples

HTML
<form>
  <select id="myFormControl" type="textarea">
    <option id="o1">Opt 1</option>
    <option id="o2">Opt 2</option>
  </select>
</form>
CSS
elem1 = document.forms[0]["myFormControl"][1]; // Returns the HTMLOptionElement representing #o2

Specifications

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'HTMLSelectElement.item()' in that specification.
Living Standard No change since the latest snapshot, HTML5.
HTML5
The definition of 'HTMLSelectElement.item()' in that specification.
Recommendation Initial definition, snapshot of WHATWG HTML Living Standard

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) 4.0 (2.0) (Yes) (Yes) ?
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support (Yes) 4.0 (2.0) (Yes) (Yes) ?

 

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/htmlselectelement/item

API HTML DOM HTMLSelectElement Method Reference Référence