Source Code:
(back to article)
<!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> <template id="tmpId"> <script> alert("Welcome to W3Docs"); </script> <div class="message">Welcome to W3Docs!</div> </template> <script> let elem = document.createElement('div'); // Clone the contents of the template to use it several times elem.append(tmpId.content.cloneNode(true)); document.body.append(elem); // Now the script from <template> is run </script> </body> </html>
Result:
Report an issue