回答編集履歴
3
追記
test
CHANGED
@@ -47,3 +47,63 @@
|
|
47
47
|
</script>
|
48
48
|
|
49
49
|
```
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
---
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
<style>
|
60
|
+
|
61
|
+
.toggle-button > button {
|
62
|
+
|
63
|
+
display: none;
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
.toggle-button > button.active {
|
68
|
+
|
69
|
+
display: inline;
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
</style>
|
74
|
+
|
75
|
+
<div class="toggle-button">
|
76
|
+
|
77
|
+
<button class="active">A</button>
|
78
|
+
|
79
|
+
<button>B</button>
|
80
|
+
|
81
|
+
</div>
|
82
|
+
|
83
|
+
<script>
|
84
|
+
|
85
|
+
$(function(){
|
86
|
+
|
87
|
+
$('.toggle-button > button').on('click', function(){
|
88
|
+
|
89
|
+
$('.toggle-button > button').each(function(){
|
90
|
+
|
91
|
+
if ($(this).hasClass('active')) {
|
92
|
+
|
93
|
+
$(this).removeClass('active');
|
94
|
+
|
95
|
+
} else {
|
96
|
+
|
97
|
+
$(this).addClass('active');
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
});
|
102
|
+
|
103
|
+
});
|
104
|
+
|
105
|
+
});
|
106
|
+
|
107
|
+
</script>
|
108
|
+
|
109
|
+
```
|
2
修正
test
CHANGED
@@ -30,6 +30,8 @@
|
|
30
30
|
|
31
31
|
</div>
|
32
32
|
|
33
|
+
|
34
|
+
|
33
35
|
<script>
|
34
36
|
|
35
37
|
$(function(){
|
1
追記
test
CHANGED
@@ -5,3 +5,43 @@
|
|
5
5
|
|
6
6
|
|
7
7
|
[http://semooh.jp/jquery/api/attributes/toggleClass/class/](http://semooh.jp/jquery/api/attributes/toggleClass/class/)
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
```html
|
16
|
+
|
17
|
+
<style>
|
18
|
+
|
19
|
+
.text-red {
|
20
|
+
|
21
|
+
color: red;
|
22
|
+
|
23
|
+
}
|
24
|
+
|
25
|
+
</style>
|
26
|
+
|
27
|
+
<div>
|
28
|
+
|
29
|
+
<p id='toggle_class'>この要素にイベントをつける</p>
|
30
|
+
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<script>
|
34
|
+
|
35
|
+
$(function(){
|
36
|
+
|
37
|
+
$('#toggle_class').on('click', function(){
|
38
|
+
|
39
|
+
$(this).toggleClass('text-red');
|
40
|
+
|
41
|
+
});
|
42
|
+
|
43
|
+
});
|
44
|
+
|
45
|
+
</script>
|
46
|
+
|
47
|
+
```
|