1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
---
title: HTMLOptionElement
slug: Web/API/HTMLOptionElement
translation_of: Web/API/HTMLOptionElement
---
<div>{{APIRef("HTML DOM")}}</div>
<p>The <strong><code>HTMLOptionElement</code></strong> interface represents {{HTMLElement("option")}} elements and inherits all classes and methods of the {{domxref("HTMLElement")}} interface.</p>
<p>{{InheritanceDiagram(600, 120)}}</p>
<h2 id="Properties">Properties</h2>
<p><em>Inherits properties from its parent, {{domxref("HTMLElement")}}.</em></p>
<dl>
<dt>{{domxref("HTMLOptionElement.defaultSelected")}}</dt>
<dd>Is a {{domxref("Boolean")}} that contains the initial value of the {{htmlattrxref("selected", "option")}} HTML attribute, indicating whether the option is selected by default or not.</dd>
<dt>{{domxref("HTMLOptionElement.disabled")}}</dt>
<dd>Is a {{domxref("Boolean")}} representing the value of the {{htmlattrxref("disabled", "option")}} HTML attribute, which indicates that the option is unavailable to be selected. An option can also be disabled if it is a child of an {{HTMLElement("optgroup")}} element that is disabled.</dd>
<dt>{{domxref("HTMLOptionElement.form")}} {{readonlyInline}}</dt>
<dd>Is a {{domxref("HTMLFormElement")}} representing the same value as the <code>form</code> of the corresponding {{HTMLElement("select")}} element, if the option is a descendant of a {{HTMLElement("select")}} element, or null if none is found.</dd>
<dt>{{domxref("HTMLOptionElement.index")}} {{readonlyInline}}</dt>
<dd>Is a <code>long</code> representing the position of the option within the list of options it belongs to, in tree-order. If the option is not part of a list of options, like when it is part of the {{HTMLElement("datalist")}} element, the value is <code>0</code>.</dd>
<dt>{{domxref("HTMLOptionElement.label")}} {{readonlyInline}}</dt>
<dd>Is a {{domxref("DOMString")}} that reflects the value of the {{htmlattrxref("label", "option")}} HTML attribute, which provides a label for the option. If this attribute isn't specifically set, reading it returns the element's text content.</dd>
<dt>{{domxref("HTMLOptionElement.selected")}}</dt>
<dd>Is a {{domxref("Boolean")}} that indicates whether the option is currently selected.</dd>
<dt>{{domxref("HTMLOptionElement.text")}}</dt>
<dd>Is a {{domxref("DOMString")}} that contains the text content of the element.</dd>
<dt>{{domxref("HTMLOptionElement.value")}}</dt>
<dd>Is a {{domxref("DOMString")}} that reflects the value of the {{htmlattrxref("value", "option")}} HTML attribute, if it exists; otherwise reflects value of the {{domxref("Node.textContent")}} property.</dd>
</dl>
<h2 id="Methods">Methods</h2>
<p><em>Inherits methods from its parent, {{domxref("HTMLElement")}}.</em></p>
<dl>
<dt>Option()</dt>
<dd>Is a constructor creating an <code>HTMLOptionElement</code> object. It has four values: the text to display, <code>text</code>, the value associated, <code>value</code>, the value of <code>defaultSelected</code>, and the value of <code>selected</code>. The last three values are optional.</dd>
</dl>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('HTML WHATWG', "#htmloptionelement", "HTMLOptionElement")}}</td>
<td>{{Spec2('HTML WHATWG')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('HTML5 W3C', "forms.html#the-option-element", "HTMLOptionElement")}}</td>
<td>{{Spec2('HTML5 W3C')}}</td>
<td>A constructor, <code>Option()</code>, has been added.<br>
The <code>form</code> property can be the <code>null</code> value.</td>
</tr>
<tr>
<td>{{SpecName('DOM2 HTML', 'html.html#ID-70901257', 'HTMLOptionElement')}}</td>
<td>{{Spec2('DOM2 HTML')}}</td>
<td>The <code>selected</code> property changed its meaning: it now indicates if the option is currently selected and no longer if it was initally selected.<br>
The <code>defaultSelected</code> property is no longer read-only.</td>
</tr>
<tr>
<td>{{SpecName('DOM1', 'level-one-html.html#ID-70901257', 'HTMLOptionElement')}}</td>
<td>{{Spec2('DOM1')}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.HTMLOptionElement")}}</p>
<h2 id="See_also">See also</h2>
<ul>
<li>The HTML element implementing this interface: {{HTMLElement("option")}}.</li>
</ul>
|