回答編集履歴
1
コード追記
answer
CHANGED
@@ -1,9 +1,19 @@
|
|
1
|
-
親が同一階層なら、
|
1
|
+
親が同一階層なら、前回の応用で、
|
2
|
-
```
|
2
|
+
```js
|
3
3
|
$(function(){
|
4
4
|
$('.box').on('click', function () {
|
5
5
|
$(this).parent().siblings().children('.box').removeClass('active');
|
6
6
|
$(this).toggleClass('active');
|
7
7
|
});
|
8
8
|
});
|
9
|
+
```
|
10
|
+
下記だと同一階層でなくても有効です。
|
11
|
+
|
12
|
+
```js
|
13
|
+
$(function(){
|
14
|
+
$('.box').on('click', function () {
|
15
|
+
$('.box').not(this).removeClass('active');
|
16
|
+
$(this).toggleClass('active');
|
17
|
+
});
|
18
|
+
});
|
9
19
|
```
|