Skip to main content

HTMLOptionsCollection

The HTMLOptionsCollection interface represents a collection of <option> HTML elements (in document order) and offers methods and properties for selecting from the list as well as optionally altering its items. This object is returned only by the options property of select.

MDN Reference

Extends

Indexable

[index: number]: HTMLOptionElement

Methods

[iterator]()

iterator: ArrayIterator<HTMLOptionElement>;

Returns

ArrayIterator<HTMLOptionElement>

Inherited from

HTMLCollectionOf.[iterator]


add()

add(element, before?): void;

The add() method of the HTMLOptionsCollection interface adds an HTMLOptionElement or HTMLOptGroupElement to this HTMLOptionsCollection.

MDN Reference

Parameters

ParameterType
element| HTMLOptGroupElement | HTMLOptionElement
before?number | HTMLElement | null

Returns

void


item()

item(index): HTMLOptionElement | null;

The HTMLCollection method item() returns the element located at the specified offset into the collection.

MDN Reference

Parameters

ParameterType
indexnumber

Returns

HTMLOptionElement | null

Inherited from

HTMLCollectionOf.item


namedItem()

namedItem(name): HTMLOptionElement | null;

Parameters

ParameterType
namestring

Returns

HTMLOptionElement | null

Inherited from

HTMLCollectionOf.namedItem


remove()

remove(index): void;

The remove() method of the HTMLOptionsCollection interface removes the <option> element specified by the index from this collection.

MDN Reference

Parameters

ParameterType
indexnumber

Returns

void

Properties

length

length: number;

The length property of the HTMLOptionsCollection interface returns the number of <option> elements in the collection. The property can get or set the size of the collection.

MDN Reference

Overrides

HTMLCollectionOf.length


selectedIndex

selectedIndex: number;

The selectedIndex property of the HTMLOptionsCollection interface is the numeric index of the first selected <option> element, if any, or −1 if no <option> is selected. Setting this property selects the option at that index and deselects all other options in this collection, while setting it to -1 deselects any currently selected elements. It is exactly equivalent to the selectedIndex property of the HTMLSelectElement that owns this collection.

MDN Reference