回答編集履歴

2

chousei

2021/06/10 11:13

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -9,3 +9,53 @@
9
9
  何を引き継ぎたいかわかりませんが、h1~h3の中の必要な情報を
10
10
 
11
11
  liに書き出してください
12
+
13
+
14
+
15
+ # sample
16
+
17
+ ```javascript
18
+
19
+ <script>
20
+
21
+ window.addEventListener('DOMContentLoaded', ()=>{
22
+
23
+ document.querySelector('#test_section').querySelectorAll('h1,h2,h3').forEach(x=>{
24
+
25
+ const li=Object.assign(document.createElement('li'),{textContent:x.textContent});
26
+
27
+ document.querySelector('#test_ul').appendChild(li);
28
+
29
+ });
30
+
31
+ });
32
+
33
+ </script>
34
+
35
+ <div id="test_section">
36
+
37
+ <div id="test_div1">
38
+
39
+ <h1>h1 a</h1>
40
+
41
+ <h2>h2 b</h2>
42
+
43
+ <h3>h3 c</h3>
44
+
45
+ <h3>h3 d</h3>
46
+
47
+ <h2>h2 e</h2>
48
+
49
+ <h3>h3 f</h3>
50
+
51
+ <h3>h3 g</h3>
52
+
53
+ </div>
54
+
55
+ <ul id="test_ul">
56
+
57
+ </ul>
58
+
59
+ </div>
60
+
61
+ ```

1

調整

2021/06/10 11:13

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -3,3 +3,9 @@
3
3
 
4
4
 
5
5
  既存のDOMをappendChildするということは移動するということです
6
+
7
+ ulにh1~h3をそのままアペンドするというのもありえません
8
+
9
+ 何を引き継ぎたいかわかりませんが、h1~h3の中の必要な情報を
10
+
11
+ liに書き出してください