Option()
Constructor for creating an HTMLOptionElement. The Option constructor is from the very early days of DOM scripting and has non–standard syntax, but has ubiquitous support in browsers.
Syntax
JavaScript
Copy Code
var o</code>ptionElementReference<code> = new Option([<var>text</var>, [<var>value</var>, [<var>defaultSelected, [selected]]]</var>]);
Return value and parameters
- optionElementReference
- A reference to the newly created HTMLOptionElement.
- text
- A string that sets the content of the element, i.e. the displayed text.
- value
- A string that sets the
value
attribute. - defaultSelected
- A boolean that sets the
selected
attribute, the default isfalse
. A value oftrue
does not set the option to selected. - selected
- A boolean that sets the option's selected state, the default is
false
(not selected). If omitted, even if thedefaultSelected
argument is true, the option is not selected.
Specification
Specification | Status | Comment |
---|---|---|
HTML5 The definition of 'Option' in that specification. |
Recommendation |
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/htmloptionelement/option