Skip to content

Instantly share code, notes, and snippets.

@miladvafaeifard
Created November 30, 2018 11:27
Show Gist options
  • Save miladvafaeifard/286cf711e91e55e143e7c46fc5252404 to your computer and use it in GitHub Desktop.
Save miladvafaeifard/286cf711e91e55e143e7c46fc5252404 to your computer and use it in GitHub Desktop.
Using custom elements
class WordCound extends HTMLElement {
constructor() {
super();
var shadowRoot = this.attachShadow({ mode: "open" });
var p = document.createElement("p");
p.textContent = "Hello World";
p.setAttribute("class", "red-color");
var style = document.createElement("style");
style.textContent = `
.red-color {
color: red;
}
`;
shadowRoot.appendChild(style);
shadowRoot.appendChild(p);
}
}
window.customElements.define("text-info", WordCound);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment