class HelloSayerComponent extends HTMLElement { static observedAttributes = ["name"]; constructor() { super(); this.root = this.attachShadow({mode: "open"}); this.root.innerHTML = `
Hello!
`; } attributeChangedCallback(name, oldValue, newValue) { this.root.querySelector("div").innerHTML = `Hello ${newValue}!`; } } window.customElements.define("hello-sayer", HelloSayerComponent); const names = ["Joe", "Allie"]; let counter = 0; setInterval(() => document.querySelector("hello-sayer").setAttribute("name", names[counter++ % 2]), 2000);