Web Components & Shadow DOM
How do you observe attribute changes in a Custom Element?
class MyElement extends HTMLElement {
static get observedAttributes() {
return ['size', 'color'];
}
attributeChangedCallback(name, oldValue, newValue) {
if (name === 'size') this.style.fontSize = newValue + 'px';
if (name === 'color') this.style.color = newValue;
}
}