Created
November 30, 2018 11:27
-
-
Save miladvafaeifard/286cf711e91e55e143e7c46fc5252404 to your computer and use it in GitHub Desktop.
Using custom elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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