回答編集履歴

2

typo: beforeand -> beforeend

2023/03/16 07:20

投稿

int32_t
int32_t

スコア20850

test CHANGED
@@ -1,6 +1,6 @@
1
1
  `appendChild()` には HTML ソースをパーズする機能はないので、そういう機能を持った関数を使いましょう。
2
2
  ```js
3
- body.insertAdjacentHTML('beforeand', template);
3
+ body.insertAdjacentHTML('beforeend', template);
4
4
  ```
5
5
  ----
6
6
  この場合、`<template>` を使うのが相応しいかもしれません。

1

<template>

2023/03/13 15:08

投稿

int32_t
int32_t

スコア20850

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