回答編集履歴

1

追加

2021/06/17 00:34

投稿

yambejp
yambejp

スコア114951

test CHANGED
@@ -16,7 +16,31 @@
16
16
 
17
17
  });
18
18
 
19
+ </script>
19
20
 
21
+ <p>p1<strong><br>こんにちは</strong>p2</p>
22
+
23
+ ```
24
+
25
+ どのHTML要素のデータか明示するならこう
26
+
27
+ ```javascript
28
+
29
+ <script>
30
+
31
+ window.addEventListener('DOMContentLoaded', ()=>{
32
+
33
+ const txt=[];
34
+
35
+ document.querySelectorAll('body *').forEach(x=>{
36
+
37
+ txt.push({node:x.nodeName,text:[...x.childNodes].filter(x=>x.nodeType==3).map(x=>x.nodeValue)});
38
+
39
+ });
40
+
41
+ console.log(txt);
42
+
43
+ });
20
44
 
21
45
  </script>
22
46