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.
Extends
Indexable
[index: number]: HTMLOptionElement
Methods
[iterator]()
iterator: ArrayIterator<HTMLOptionElement>;
Returns
ArrayIterator<HTMLOptionElement>
Inherited from
add()
add(element, before?): void;
The add() method of the HTMLOptionsCollection interface adds an HTMLOptionElement or HTMLOptGroupElement to this HTMLOptionsCollection.
Parameters
| Parameter | Type |
|---|---|
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.
Parameters
| Parameter | Type |
|---|---|
index | number |
Returns
HTMLOptionElement | null
Inherited from
namedItem()
namedItem(name): HTMLOptionElement | null;
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
HTMLOptionElement | null
Inherited from
remove()
remove(index): void;
The remove() method of the HTMLOptionsCollection interface removes the <option> element specified by the index from this collection.
Parameters
| Parameter | Type |
|---|---|
index | number |
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.
Overrides
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.