回答編集履歴
3
びちょうせい
test
CHANGED
@@ -12,9 +12,9 @@
|
|
12
12
|
|
13
13
|
document.addEventListener('click',e=>{
|
14
14
|
|
15
|
-
|
15
|
+
const t=e.target;
|
16
16
|
|
17
|
-
if(
|
17
|
+
if(t.closest('.bookAdd')){
|
18
18
|
|
19
19
|
const newLi=document.createElement('li');
|
20
20
|
|
@@ -34,10 +34,10 @@
|
|
34
34
|
|
35
35
|
}
|
36
36
|
|
37
|
-
|
37
|
+
t.closest('.deleteBook')?.closest('li').remove();
|
38
38
|
|
39
39
|
});
|
40
40
|
|
41
|
+
```
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
※一部調整
|
2
chousei
test
CHANGED
@@ -10,9 +10,9 @@
|
|
10
10
|
|
11
11
|
```javascript
|
12
12
|
|
13
|
-
document.addEventListener('click',
|
13
|
+
document.addEventListener('click',e=>{
|
14
14
|
|
15
|
-
let bookAddSystem
|
15
|
+
let bookAddSystem;
|
16
16
|
|
17
17
|
if(bookAddSystem=e.target.closest('.bookAdd')){
|
18
18
|
|
@@ -34,12 +34,10 @@
|
|
34
34
|
|
35
35
|
}
|
36
36
|
|
37
|
-
|
37
|
+
e.target.closest('.deleteBook')?.closest('li').remove();
|
38
|
-
|
39
|
-
deleteLi.remove();
|
40
|
-
|
41
|
-
}
|
42
38
|
|
43
39
|
});
|
44
40
|
|
41
|
+
|
42
|
+
|
45
43
|
```
|
1
sample
test
CHANGED
@@ -1,3 +1,45 @@
|
|
1
1
|
追加をクリックしないと削除ボタンが作成されないのに
|
2
2
|
|
3
3
|
削除ボタンにクリックイベントを設定しようとしています
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
# sample
|
8
|
+
|
9
|
+
//sample.js
|
10
|
+
|
11
|
+
```javascript
|
12
|
+
|
13
|
+
document.addEventListener('click',(e)=>{
|
14
|
+
|
15
|
+
let bookAddSystem,deleteLi;
|
16
|
+
|
17
|
+
if(bookAddSystem=e.target.closest('.bookAdd')){
|
18
|
+
|
19
|
+
const newLi=document.createElement('li');
|
20
|
+
|
21
|
+
document.querySelector('.taskAdd').appendChild(newLi);
|
22
|
+
|
23
|
+
const value=document.querySelector('.bookText').value;
|
24
|
+
|
25
|
+
[new Text(value),
|
26
|
+
|
27
|
+
Object.assign(document.createElement('textarea'),{value}),
|
28
|
+
|
29
|
+
Object.assign(document.createElement('button'),{className:'deleteBook',textContent:'削除'}),
|
30
|
+
|
31
|
+
Object.assign(document.createElement('button'),{textContent:'編集'}),
|
32
|
+
|
33
|
+
].forEach(x=>newLi.appendChild(x));
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
if(deleteLi=e.target.closest('.deleteBook')?.closest('li')){
|
38
|
+
|
39
|
+
deleteLi.remove();
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
});
|
44
|
+
|
45
|
+
```
|