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
text
property of the Option object.-
value
An optional string argument that specifies the
value
property of the Option object.-
defaultSelected
An optional boolean argument that specifies the
defaultSelected
property of the Option object.-
selected
An optional boolean argument that specifies the
selected
property of the Option object.
Properties
-
boolean defaultSelected
The initial value of the
selected
attribute of the<option>
element. If the form is reset, theselected
property is reset to the value of this property. Setting this property also sets the value of theselected
property.-
boolean disabled
If
true
, this<option>
element is disabled, and the user is not allowed to select it. Mirrors thedisabled
attribute.-
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
label
attribute. If this property is not specified, the ...
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.