aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/htmlselectelement/options/index.html
blob: 9104769ff0f4a08cc56580e56f7e61b9b4bd1e4a (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
title: HTMLSelectElement.options
slug: Web/API/HTMLSelectElement/options
tags:
  - API
  - HTMLSelectElement
  - Options
  - Property
  - Read-only
  - Web
  - ウェブ
  - プロパティ
translation_of: Web/API/HTMLSelectElement/options
---
<div>{{APIRef("DOM")}}</div>

<p><code><strong>HTMLSelectElement.options</strong></code> は読み取り専用のプロパティで、 {{HTMLElement("select")}} 要素に含まれる {{HTMLElement("option")}} 要素の {{domxref("HTMLOptionsCollection")}} を返します。</p>

<h2 id="Syntax" name="Syntax">構文</h2>

<pre class="syntaxbox">var <var>options</var> = <var>select</var>.options;
</pre>

<h3 id="Return_value" name="Return_value">返値</h3>

<p><code>&lt;select&gt;</code> 要素に含まれる <code>&lt;option&gt;</code> 要素の {{domxref("HTMLOptionsCollection")}} です。</p>

<h2 id="Example" name="Example"></h2>

<h3 id="HTML">HTML</h3>

<pre class="brush: html">&lt;label for="test"&gt;Label&lt;/label&gt;
&lt;select id="test"&gt;
  &lt;option value="1"&gt;Option 1&lt;/option&gt;
  &lt;option value="2"&gt;Option 2&lt;/option&gt;
&lt;/select&gt;
</pre>

<h3 id="JavaScript">JavaScript</h3>

<pre class="brush: js">window.addEventListener("DOMContentLoaded", function() {
  const select = document.getElementById("test");
  for(var i = 0; i &lt; select.options.length; i++) {
    console.log(select.options[i].label); // "Option 1" and "Option 2"
  }
});</pre>

<p>{{EmbedLiveSample("Example", "100%", 30)}}</p>

<h2 id="Specifications" name="Specifications">仕様書</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">仕様書</th>
   <th scope="col">状態</th>
   <th scope="col">備考</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("HTML WHATWG", "form-elements.html#the-select-element:htmloptionscollection", "options")}}</td>
   <td>{{Spec2("HTML WHATWG")}}</td>
   <td>変更なし</td>
  </tr>
  <tr>
   <td>{{SpecName("HTML5 W3C", "forms.html#htmlselectelement", "options")}}</td>
   <td>{{Spec2("HTML5 W3C")}}</td>
   <td>初回定義</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの対応</h2>

<p>{{Compat("api.HTMLSelectElement.options")}}</p>