-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
51 lines (37 loc) · 1.04 KB
/
index.md
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
---
title: "HTMLSelectElement: options property"
short-title: options
slug: Web/API/HTMLSelectElement/options
page-type: web-api-instance-property
browser-compat: api.HTMLSelectElement.options
---
{{APIRef("DOM")}}
The **`HTMLSelectElement.options`** read-only property returns
a {{domxref("HTMLOptionsCollection")}} of the {{HTMLElement("option")}} elements
contained by the {{HTMLElement("select")}} element.
## Value
A {{domxref("HTMLOptionsCollection")}} containing the `<option>`
elements contained by the `<select>` element.
## Examples
### HTML
```html
<label for="test">Label</label>
<select id="test">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
```
### JavaScript
```js
window.addEventListener("DOMContentLoaded", () => {
const select = document.getElementById("test");
for (const option of select.options) {
console.log(option.label); // "Option 1" and "Option 2"
}
});
```
{{EmbedLiveSample("Examples", "100%", 30)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}