Constructor for creating an HTMLOptionElement
.
Syntax
var o
ptionElementReference= new Option(text, value, defaultSelected, selected);
Parameters
- text Optional
- A
DOMString
representing the content of the element, i.e. the displayed text. If this is not specified, a default value of "" (empty string) is used. - value Optional
- A
DOMString
representing the value of theHTMLOptionElement
, i.e. thevalue
attribute of the equivalent<option>
. If this is not specified, the value of text is used as the value, e.g. for the associated<select>
element's value when the form is submitted to the server. - defaultSelected Optional
- A
Boolean
that sets theselected
attribute value, i.e. so that this<option>
will be the default value selected in the<select>
element when the page is first loaded. If this is not specified, a default value offalse
is used. Note that a value oftrue
does not set the option to selected if it is not already selected. - selected Optional
- A
Boolean
that sets the option's selected state; the default isfalse
(not selected). If omitted, even if thedefaultSelected
argument istrue
, the option is not selected.
Specification
Specification | Status | Comment |
---|---|---|
HTML5 The definition of 'Option' in that specification. |
Recommendation |