JavaScript
Result
Run
License
class CustomTitle extends HTMLHeadingElement { constructor() { super(); this.style.color = "red"; } connectedCallback() { const elSpan = document.createElement("span"); elSpan.style.color = "blue"; elSpan.textContent = this.dataset.content; this.attachShadow({ mode: "open" }).append(this.textContent, elSpan); } } window.addEventListener("load", function() { customElements.define("custom-title", CustomTitle, { extends: "h1"}); var elH1 = document.createElement("h1", { is: "custom-title"} ); elH1.setAttribute("data-content", ", everyone"); elH1.textContent = "Welcome"; document.body.appendChild(elH1); });
Console
expand_less
License
License
by DevDic
Close