option
elementselect
element.datalist
element.optgroup
element.disabled
label
selected
value
[NamedConstructor=Option(), NamedConstructor=Option(DOMString text), NamedConstructor=Option(DOMString text, DOMString value), NamedConstructor=Option(DOMString text, DOMString value, boolean defaultSelected), NamedConstructor=Option(DOMString text, DOMString value, boolean defaultSelected, boolean selected)] interface HTMLOptionElement : HTMLElement { attribute boolean disabled; readonly attribute HTMLFormElement? form; attribute DOMString label; attribute boolean defaultSelected; attribute boolean selected; attribute DOMString value; attribute DOMString text; readonly attribute long index; };
The option
element represents
an option in a select
element or as part of a list of
suggestions in a datalist
element.
In certain circumstances described in the definition of the
select
element, an option
element can be a select
element's placeholder label option. A
placeholder label option does
not represent an actual option, but instead represents a label for
the select
control.
The disabled
attribute is a
boolean attribute. An option
element is disabled if its disabled
attribute is present or if it
is a child of an optgroup
element whose disabled
attribute is present.
The label
attribute provides a
label for element. The label of an option
element is the value of the
label
content attribute, if there is one,
or, if there is not, the value of the element's text
IDL attribute.
The value
attribute provides a
value for element. The value of an option
element is the value of the
value
content attribute, if there is one,
or, if there is not, the value of the element's text
IDL attribute.
The selected
attribute is a
boolean attribute. It represents the
default selectedness of the
element.
A select
element whose multiple
attribute is not specified
must not have more than one descendant option
element with its selected
attribute set.
selected
Returns true if the element is selected, and false otherwise.
Can be set, to override the current state of the element.
index
Returns the index of the element in its select
element's options
list.
form
Returns the element's form
element, if any, or null
otherwise.
text
Same as textContent
,
except that spaces are collapsed.
Option
(
[ text [, value [,
defaultSelected [, selected
] ] ] ] )Returns a new option
element.
The text argument sets the contents of the element.
The value argument sets the value
attribute.
The defaultSelected argument sets the
selected
attribute.
The selected argument sets whether or not the element is selected. If it is omitted, even if the defaultSelected argument is true, the element is not selected.