Name
HTMLOptionsCollection — a collection of Option elements
Inherits from
HTMLCollection
Synopsis
HTMLOptionsCollection is a specialized HTMLCollection that
represents the Option elements within a Select element. It overrides the namedItem() method to handle multiple
Option elements with the same name, and it defines methods for
adding and removing elements. For historical reasons,
HTMLOptionsCollection defines a writable length property that you can set to
truncate or extend the collection.
Properties
unsigned longlengthThis property returns the number of elements in the collection. Unlike the
lengthproperty of a regular HTMLCollection, however, this one is not read-only. If you set it to a value smaller than its current value, the collection of Option elements is truncated, and those that are no longer in the collection are removed from the containing Select element. If you setlengthto a value larger than its current value, empty<option/>elements are created and added to the Select element and to the collection.longselectedIndexThe index of the first selected Option in the collection, or -1 if no Option is selected. You can set this property to change the selected item.
Methods
void add(Element
option, [any
before])
add(Element
option, [any
before])Insert the option (which must be
an <option> or <optgroup> element) into this
collection (and into the Select element) at the position specified
by before. If
before is null, insert it at the end.
If before is an integer index, insert it before the item that is currently ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access