aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/htmlselectelement/labels/index.md
blob: 6402994378c12c9718e954bf9af2d45229807f5c (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.labels
slug: Web/API/HTMLSelectElement/labels
tags:
  - API
  - HTML DOM
  - HTMLSelectElement
  - プロパティ
  - リファレンス
browser-compat: api.HTMLSelectElement.labels
translation_of: Web/API/HTMLSelectElement/labels
---
{{APIRef("DOM")}}

**`HTMLSelectElement.labels`** は読み取り専用のプロパティで、{{HTMLElement("select")}} 要素に関連付けられた {{HTMLElement("label")}} 要素の {{domxref("NodeList")}} を返します。

## 構文

```js
var labelElements = select.labels;
```

### 返値

{{domxref("NodeList")}} で、`<select>` 要素に関連付けられた `<label>` 要素が入ります。

## 例

### HTML

```html
<label id="label1" for="test">Label 1</label>
<select id="test">
  <option value="1">Option 1</option>
  <option value="2">Option 2</option>
</select>
<label id="label2" for="test">Label 2</label>
```

### JavaScript

```js
window.addEventListener("DOMContentLoaded", function() {
  const select = document.getElementById("test");
  for(var i = 0; i < select.labels.length; i++) {
    console.log(select.labels[i].textContent); // "Label 1" and "Label 2"
  }
});
```

{{EmbedLiveSample("Example", "100%", 30)}}

## 仕様書

{{Specifications}}

## ブラウザーの互換性

{{Compat}}