Name

Option — an <option> in a Select element

Inherits from

Node, Element

Synopsis

The Option object describes a single option displayed within a Select object. The properties of this object specify whether it is selected by default, whether it is currently selected, the position it has in the options[] array of its containing Select object, the text it displays, and the value it passes to the server if it is selected when the containing form is submitted.

For historical reasons, the Option element defines a constructor that you can use to create and initialize new Option elements. (You can also use the normal Document.create Element() method, of course.) Once a new Option object is created, it can be appended to the options collection of a Select object. See HTMLOptionsCollection for details.

Constructor

new Option([string text, string value, boolean defaultSelected, boolean selected])

The Option() constructor creates an <option> element. The four optional argument specify the textContent (see Node) of the element and the initial values of the value, default Selected and selected properties.

Properties

boolean defaultSelected

This property mirrors the HTML selected attribute. It defines the initial selectedness of the option, and also the value that is used when the form is reset.

boolean disabled

true if this option is disabled. Options are disabled if they or a containing <optgroup> has the HTML disabled attribute.

readonly Form form

The <form> element, if any, of which this Option element ...

Get JavaScript: The Definitive Guide, 6th 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.