Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<div id="parent">
  <h1>Parent</h1>
</div>
<template id="my-template">
  <h2>My First Template</h2>
  <script>
    console.log("template script output");
  </script>
</template>
<script>
/*
  get the current document (needed as we'll be importing this
  file later), you could just use document if not importing
*/
const currentDocument = document.currentScript.ownerDocument;
const parent = currentDocument.getElementById('parent');
const template = currentDocument.getElementById('my-template');
/*
  stamping out an instance of our template
*/
const instance = template.content.cloneNode(true);
console.log('template instance created');
/*
  the script inside our template won't run until out template
  instance is inserted into the DOM
*/
parent.appendChild(instance);
  
</script>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
lamplightdevpro
0viewers