Skip to content

Instantly share code, notes, and snippets.

@JCrestel
Last active June 29, 2017 13:07
Show Gist options
  • Save JCrestel/b4206e5b20b874a5793f9abcffe8f7c3 to your computer and use it in GitHub Desktop.
Save JCrestel/b4206e5b20b874a5793f9abcffe8f7c3 to your computer and use it in GitHub Desktop.
<template id="hello-world">
<p>Hello World</p>
</template>
<script>
const templateHelloWorld = (document.currentScript || document._currentScript)
.ownerDocument.querySelector('#hello-world').content;
class HelloWorld extends HTMLElement {
connectedCallback() {
let shadowRoot = this.attachShadow({mode: 'open'});
const content = document.importNode(templateHelloWorld, true);
this.shadowRoot.appendChild(content);
}
};
window.customElements.define('hello-world', HelloWorld);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment