W3cubDocs

/Web APIs

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.

HTMLCollection HTMLOptionsCollection

Instance properties

HTMLOptionsCollection.length

Returns or sets the number of options in the collection.

HTMLOptionsCollection.selectedIndex

The index number of the first selected <option> element. The value -1 indicates no element is selected.

Instance methods

This interface inherits the methods of its parent, HTMLCollection.

HTMLOptionsCollection.add()

Appends an HTMLOptionElement or HTMLOptGroupElement element to the collection of option elements or adds it before a specified option.

HTMLOptionsCollection.remove()

Removes the element at the specified index from the options collection.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
HTMLOptionsCollection 1 12 1 ≤12.1 3 18 4 ≤12.1 1 1.0 4.4 1
add 1 12 1 ≤12.1 3 18 4 ≤12.1 1 1.0 4.4 1
length 1 12 1 ≤12.1 3 18 4 ≤12.1 1 1.0 4.4 1
remove 1 12 4 ≤12.1 3.1 18 4 ≤12.1 1 1.0 4.4 1
selectedIndex 1 12 1 ≤12.1 3 18 4 ≤12.1 1 1.0 4.4 1

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionsCollection