Skip to content

Instantly share code, notes, and snippets.

@Danetag
Created May 20, 2020 00:19
Show Gist options
  • Save Danetag/9c39d314bdb8428d96a1200940739eba to your computer and use it in GitHub Desktop.
Save Danetag/9c39d314bdb8428d96a1200940739eba to your computer and use it in GitHub Desktop.
<!-- Template definition -->
<template id="fancy-element-template">
<style>
...
</style>
<div class="container">
<p>Some fancy markup goes here...</p>
</div>
</template>
<script>
customElements.define('fancy-element', class extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({mode: 'open'});
const t = document.querySelector('#fancy-element-template');
const instance = t.content.cloneNode(true);
shadowRoot.appendChild(instance);
}
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment