cloneNode()
The DOM method that copies a node; with the argument true it copies the whole subtree as well.
In more detail
template.content.cloneNode(true) produces a fresh, independent copy of the blueprint each time. Event listeners added with addEventListener are not copied.
Related terms
- template element — An HTML element whose contents are parsed but not rendered or run, kept as a reusable blueprint that scripts copy into the page.
- DocumentFragment — A lightweight container for DOM nodes that is not part of the page, used to build many nodes and insert them all in one step.
Taught in
- DOM Manipulation: DocumentFragment And HTML Templates — Frontend Architecture & Web Platform