자바스크립트 cloneNode & appendChild

1 개요[ | ]

자바스크립트 cloneNode & appendChild
<div id="container">
  <div id="apple">Apple</div>
  <div id="banana">Banana</div>
</div>

<script>
const clone = document.getElementById("apple").cloneNode(true);
document.getElementById("container").appendChild(clone);
</script>
<div class="container">
  <div class="apple">Apple</div>
  <div class="banana">Banana</div>
</div>

<script>
const clone = document.getElementsByClassName("apple")[0].cloneNode(true);
document.getElementsByClassName("container")[0].appendChild(clone);
</script>

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}