回答編集履歴
1
jQueryとの相対性を追記
test
CHANGED
@@ -4,23 +4,39 @@
|
|
4
4
|
|
5
5
|
```js
|
6
6
|
|
7
|
-
//
|
7
|
+
// ↓ $(function() { に相当
|
8
8
|
|
9
|
-
|
9
|
+
window.addEventListener('DOMContentLoaded', function() {
|
10
10
|
|
11
|
-
$('#trigger').on('click', function() {
|
11
|
+
// ↓ $('#trigger').on('click', function() { に相当
|
12
12
|
|
13
|
-
|
13
|
+
ducument.querySelector('#trigger').addEventListener('click', function() {
|
14
14
|
|
15
|
-
$(this)
|
15
|
+
// ↓ $(this) に相当
|
16
16
|
|
17
|
+
const _this = event.currentTarget;
|
18
|
+
|
19
|
+
// ↓ $('#list') に相当
|
20
|
+
|
21
|
+
const ducument.querySelector('#list');
|
22
|
+
|
23
|
+
// ↓ if($(this).hasClass('active')) { に相当
|
24
|
+
|
25
|
+
if(_this.classList.contains('active')) {
|
26
|
+
|
27
|
+
// ↓ .removeClass(className) に相当
|
28
|
+
|
29
|
+
_this.classList.remove('active');
|
30
|
+
|
17
|
-
|
31
|
+
list.classList.remove('open');
|
18
32
|
|
19
33
|
} else {
|
20
34
|
|
21
|
-
|
35
|
+
// ↓ .addClass(className) に相当
|
22
36
|
|
37
|
+
_this.classList.add('active');
|
38
|
+
|
23
|
-
|
39
|
+
list.classList.add('open');
|
24
40
|
|
25
41
|
}
|
26
42
|
|
@@ -28,30 +44,4 @@
|
|
28
44
|
|
29
45
|
});
|
30
46
|
|
31
|
-
|
32
|
-
|
33
|
-
// Vanilla
|
34
|
-
|
35
|
-
document.getElementById('trigger').onclick = function(event) {
|
36
|
-
|
37
|
-
const _this = event.currentTarget;
|
38
|
-
|
39
|
-
const list = document.getElementById('list');
|
40
|
-
|
41
|
-
if(_this.classList.contains('active')) {
|
42
|
-
|
43
|
-
_this.classList.remove('active');
|
44
|
-
|
45
|
-
list.classList.remove('open');
|
46
|
-
|
47
|
-
} else {
|
48
|
-
|
49
|
-
_this.classList.add('active');
|
50
|
-
|
51
|
-
list.classList.add('open');
|
52
|
-
|
53
|
-
}
|
54
|
-
|
55
|
-
};
|
56
|
-
|
57
47
|
```
|