W3cubDocs

/DOM

HTMLOptionsCollection

HTMLOptionsCollection is an interface representing a collection of HTML option elements (in document order) and offers methods and properties for traversing the list as well as optionally altering its items. This type is returned solely by the "options" property of select.

Properties

Name Type Description
length unsigned long As optionally allowed by the spec, Mozilla allows this property to be set, either removing options at the end when using a shorter length, or adding blank options at the end when setting a longer length. Other implementations could potentially throw a DOMException.

Methods

  • item(index) - returns the specific node at the given zero-based index (gives null if out of range)
  • namedItem(name) - returns the specific node with the given DOMString (i.e., string) id. Returns null if no such named node exists.

Specification

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support Yes Yes Yes Yes Yes Yes
length Yes 13 Yes Yes Yes Yes
add Yes ? ? ? Yes ?
remove Yes ? ? ? Yes ?
selectedIndex Yes ? ? ? Yes ?
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support Yes Yes Yes Yes Yes Yes Yes
length Yes Yes Yes Yes Yes Yes Yes
add Yes Yes ? ? Yes ? ?
remove Yes Yes ? ? Yes ? ?
selectedIndex Yes Yes ? ? Yes ? ?

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionsCollection