回答編集履歴
1
追加
answer
CHANGED
@@ -7,7 +7,19 @@
|
|
7
7
|
});
|
8
8
|
console.log(txt);
|
9
9
|
});
|
10
|
-
|
11
10
|
</script>
|
12
11
|
<p>p1<strong><br>こんにちは</strong>p2</p>
|
12
|
+
```
|
13
|
+
どのHTML要素のデータか明示するならこう
|
14
|
+
```javascript
|
15
|
+
<script>
|
16
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
17
|
+
const txt=[];
|
18
|
+
document.querySelectorAll('body *').forEach(x=>{
|
19
|
+
txt.push({node:x.nodeName,text:[...x.childNodes].filter(x=>x.nodeType==3).map(x=>x.nodeValue)});
|
20
|
+
});
|
21
|
+
console.log(txt);
|
22
|
+
});
|
23
|
+
</script>
|
24
|
+
<p>p1<strong><br>こんにちは</strong>p2</p>
|
13
25
|
```
|