Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> <template id="myTemplate"> <p>Template content</p> </template> <div id="normalContent"> <p>First paragraph</p> </div> <!-- JavaScript function clones the template and adds it to the document. --> <button onclick="useTemplate();">Show content</button> <script> function useTemplate() { var myTemplate = document.getElementById('myTemplate'); normalContent = document.getElementById('normalContent'); clonedTemplate = myTemplate.content.cloneNode(true); normalContent.appendChild(clonedTemplate); } </script> </body> </html>