回答編集履歴
2
typo: beforeand -> beforeend
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
`appendChild()` には HTML ソースをパーズする機能はないので、そういう機能を持った関数を使いましょう。
|
2
2
|
```js
|
3
|
-
body.insertAdjacentHTML('before
|
3
|
+
body.insertAdjacentHTML('beforeend', template);
|
4
4
|
```
|
5
5
|
----
|
6
6
|
この場合、`<template>` を使うのが相応しいかもしれません。
|
1
<template>
test
CHANGED
@@ -2,4 +2,19 @@
|
|
2
2
|
```js
|
3
3
|
body.insertAdjacentHTML('beforeand', template);
|
4
4
|
```
|
5
|
+
----
|
6
|
+
この場合、`<template>` を使うのが相応しいかもしれません。
|
7
|
+
```html
|
8
|
+
<template id="t1">
|
9
|
+
<a href="">
|
10
|
+
<span class="btn">
|
11
|
+
</span>
|
12
|
+
</a>
|
13
|
+
</template>
|
14
|
+
<script>
|
15
|
+
const template = document.querySelector('#t1');
|
16
|
+
document.body.appendChild(template.content.cloneNode());
|
17
|
+
</script>
|
18
|
+
</body>
|
19
|
+
```
|
5
20
|
|