Skip to content

Instantly share code, notes, and snippets.

@emolr
Last active October 10, 2017 00:47
Show Gist options
  • Save emolr/ff11b32994dbe34cfca8f99f7d457311 to your computer and use it in GitHub Desktop.
Save emolr/ff11b32994dbe34cfca8f99f7d457311 to your computer and use it in GitHub Desktop.
class MyElement extends HTMLElement {
constructor() {
super();
// We create a shadowDOM
this.attachShadow({mode: 'open'});
// Then we inject a html template into the created ShadowDOM
this.shadowRoot.innerHTML = `
Hello, I'm a web component
`;
}
}
// Register the web component
window.customElements.define('my-element', MyElement);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment