Name
Select.options[]: the choices in a Select object â DOM Level 2 HTML
Synopsis
readonly HTMLCollection options
Description
The options[]
property is
an array-like HTMLCollection of Option objects. Each Option object
describes one of the selection options presented within the Select
object.
The options[]
property is
not an ordinary HTMLCollection. For backward compatibility with the
earliest browsers, this collection has certain special behaviors
that allow you to change the options displayed by the Select
object:
If you set
options.length
to 0, all options in the Select object are cleared.If you set
options.length
to a value less than the current value, the number of options in the Select object is decreased, and those at the end of the array disappear.If you set an element in the
options[]
array tonull
, that option is removed from the Select object, and the elements above it in the array are moved down, changing their indices to occupy the new space in the array (see alsoSelect.remove( )
).If you create a new Option object with the
Option( )
constructor (seeOption
), you can add that option to the end of the options list in the Select object by appending it to theoptions[]
array. To do this, setoptions[options.length]
(see alsoSelect.add( )
).
See Also
Option
Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.