回答編集履歴

2

ちょうせい

2021/10/14 04:29

投稿

yambejp
yambejp

スコア114572

test CHANGED
@@ -29,3 +29,31 @@
29
29
  </script>
30
30
 
31
31
  ```
32
+
33
+
34
+
35
+ # メニュー3とメニュー5を排他的に開く
36
+
37
+ ```javascript
38
+
39
+ window.addEventListener('DOMContentLoaded', ()=>{
40
+
41
+ document.querySelectorAll('#nav li>span').forEach(x=>{
42
+
43
+ x.addEventListener('click',()=>{
44
+
45
+ [...document.querySelectorAll('.subnavigation-inner')].forEach(y=>{
46
+
47
+ if(y!==x.nextElementSibling.querySelector('.subnavigation-inner')) y.classList.remove('active',);
48
+
49
+ });
50
+
51
+ x.nextElementSibling.querySelector('.subnavigation-inner')?.classList.toggle('active');
52
+
53
+ });
54
+
55
+ });
56
+
57
+ });
58
+
59
+ ```

1

chousei

2021/10/14 04:29

投稿

yambejp
yambejp

スコア114572

test CHANGED
@@ -12,11 +12,11 @@
12
12
 
13
13
  <script>
14
14
 
15
- $(function(){
15
+ window.addEventListener('DOMContentLoaded', ()=>{
16
16
 
17
17
  document.querySelectorAll('#nav li>span').forEach(x=>{
18
18
 
19
- x.addEventListener('click',e=>{
19
+ x.addEventListener('click',()=>{
20
20
 
21
21
  x.nextElementSibling.querySelector('.subnavigation-inner')?.classList.toggle('active');
22
22