blob: 1af533e1e4db0add3ec1a7be68d0754eab7d2ff5 (
plain)
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
|
---
title: HTMLSelectElement.options
slug: Web/API/HTMLSelectElement/options
tags:
- API
- HTMLSelectElement
- Options
- プロパティ
- 読み取り専用
- ウェブ
browser-compat: api.HTMLSelectElement.options
translation_of: Web/API/HTMLSelectElement/options
---
{{APIRef("DOM")}}
**`HTMLSelectElement.options`** は読み取り専用のプロパティで、{{domxref("HTMLOptionsCollection")}} で {{HTMLElement("select")}} 要素に含まれる {{HTMLElement("option")}} 要素を返します。
## 構文
```js
var options = select.options;
```
## 返値
{{domxref("HTMLOptionsCollection")}} で、`<select>` 要素に含まれる `<option>` 要素を返します。
<h2 id="Example">例</h2>
### HTML
```html
<label for="test">ラベル</label>
<select id="test">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
```
### JavaScript
```js
window.addEventListener("DOMContentLoaded", function() {
const select = document.getElementById("test");
for(var i = 0; i < select.options.length; i++) {
console.log(select.options[i].label); // "Option 1" および "Option 2"
}
});
```
{{EmbedLiveSample("Example", "100%", 30)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
|