Name
Option: an option in a Select element — DOM Level 2 HTML: Node → Element → HTMLElement → HTMLOptionElement
Constructor
Option objects can be created with Document.createElement( ), like any other
tag. In the DOM Level 0, Option objects can also be dynamically
created with the Option( )
constructor, as follows:
new Option(Stringtext, Stringvalue, booleandefaultSelected, booleanselected)
Arguments
-
text An optional string argument that specifies the
textproperty of the Option object.-
value An optional string argument that specifies the
valueproperty of the Option object.-
defaultSelected An optional boolean argument that specifies the
defaultSelectedproperty of the Option object.-
selected An optional boolean argument that specifies the
selectedproperty of the Option object.
Properties
-
boolean defaultSelected The initial value of the
selectedattribute of the<option>element. If the form is reset, theselectedproperty is reset to the value of this property. Setting this property also sets the value of theselectedproperty.-
boolean disabled If
true, this<option>element is disabled, and the user is not allowed to select it. Mirrors thedisabledattribute.-
readonlyHTMLFormElementform A reference to the
<form>element that contains this element.-
readonly long index The position of this
<option>element within the<select>element that contains it.-
String label The text to be displayed for the option. Mirrors the
labelattribute. If this property is not specified, the plain-text ...
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