Skip to content

Instantly share code, notes, and snippets.

@Tubeee
Last active December 10, 2023 06:54
Show Gist options
  • Select an option

  • Save Tubeee/601561e967377dc646790e8e4dedc647 to your computer and use it in GitHub Desktop.

Select an option

Save Tubeee/601561e967377dc646790e8e4dedc647 to your computer and use it in GitHub Desktop.
export function createCustomElement(name, templateId) {
const template = document.getElementById(templateId);
class CustomElement extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode: "open" });
shadowRoot.appendChild(template.content.cloneNode(true));
}
}
customElements.define(name, CustomElement);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment