aboutsummaryrefslogtreecommitdiff
path: root/files/ja/web/api/htmldetailselement/toggle_event/index.html
blob: 6a3c8b6e410bbcb1c73118079029b0c6a001fec0 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
title: 'HTMLDetailsElement: toggle イベント'
slug: Web/API/HTMLDetailsElement/toggle_event
tags:
  - Event
  - HTMLDetailsElement
  - Reference
  - details
  - events
  - toggle
  - イベント
translation_of: Web/API/HTMLDetailsElement/toggle_event
---
<div>{{APIRef}}</div>

<p><strong><code>toggle</code></strong> イベントは、 {{HtmlElement("details")}} 要素の <code>open</code>/<code>closed</code> の状態がトグル切り替えされたときに発生します。</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">バブリング</th>
   <td>なし</td>
  </tr>
  <tr>
   <th scope="row">キャンセル</th>
   <td>不可</td>
  </tr>
  <tr>
   <th scope="row">インターフェイス</th>
   <td>{{DOMxRef("Event")}}</td>
  </tr>
  <tr>
   <th scope="row">イベントハンドラープロパティ</th>
   <td>なし</td>
  </tr>
  <tr>
   <th>既定のアクション</th>
   <td>{{HtmlElement("details")}} 要素の <code>open</code> の状態をトグル切り替えする。</td>
  </tr>
 </tbody>
</table>

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

<p>この例は開かれた節をログ出力します。節が閉じられるとログから削除されます。</p>

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

<pre class="brush: html">&lt;aside id="log"&gt;
  &lt;b&gt;Open chapters:&lt;/b&gt;
  &lt;div data-id="ch1" hidden&gt;I&lt;/div&gt;
  &lt;div data-id="ch2" hidden&gt;II&lt;/div&gt;
  &lt;div data-id="ch3" hidden&gt;III&lt;/div&gt;
&lt;/aside&gt;
&lt;section id="summaries"&gt;
  &lt;b&gt;Chapter summaries:&lt;/b&gt;
  &lt;details id="ch1"&gt;
    &lt;summary&gt;Chapter I&lt;/summary&gt;
    Philosophy reproves Boethius for the foolishness of his complaints against Fortune. Her very nature is caprice.
  &lt;/details&gt;
  &lt;details id="ch2"&gt;
    &lt;summary&gt;Chapter II&lt;/summary&gt;
    Philosophy in Fortune's name replies to Boethius' reproaches, and proves that the gifts of Fortune are hers to give and to take away.
  &lt;/details&gt;
  &lt;details id="ch3"&gt;
    &lt;summary&gt;Chapter III&lt;/summary&gt;
    Boethius falls back upon his present sense of misery. Philosophy reminds him of the brilliancy of his former fortunes.
  &lt;/details&gt;
&lt;/section&gt;</pre>

<h3 id="CSS">CSS</h3>

<pre class="brush: css">body {
  display: flex;
  flex-direction: row-reverse;
}

#log {
  flex-shrink: 0;
  padding-left: 3em;
}

#summaries {
  flex-grow: 1;
}</pre>

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

<pre class="brush: js">function logItem(e) {
  const item = document.querySelector(`[data-id=${e.target.id}]`);
  item.toggleAttribute('hidden');
}

const chapters = document.querySelectorAll('details');
chapters.forEach((chapter) =&gt; {
  chapter.addEventListener('toggle', logItem);
});</pre>

<h3 id="Result" name="Result">結果</h3>

<p>{{EmbedLiveSample("Examples", 700, 200)}}</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', 'indices.html#event-toggle', 'toggle event')}}</td>
   <td>{{Spec2("HTML WHATWG")}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

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

<p>{{Compat("api.HTMLDetailsElement.toggle_event")}}</p>