Concepts
Instantiate a template with importNode
Creates a deep clone of the template fragment in the current document; the original remains reusable.
Formal Syntax & Structure
javascript syntaxjavascript
document.importNode(template.content, true)Return Value
DocumentFragment
Creates a deep clone of the template fragment in the current document; the original remains reusable.
Working Example
Example Snippetjavascript
(async () => {const t=document.createElement("template");t.innerHTML="<p></p>";for(const label of ["A","<B>"]){const copy=document.importNode(t.content,true);copy.querySelector("p").textContent=label;document.body.append(copy);}console.log(JSON.stringify([...document.querySelectorAll("p")].map(x=>x.textContent)),t.content.childElementCount);})()