class MyComponent extends HTMLElement { static get observedAttributes() { return ['my-attribute'] } attributeChangedCallback(name, oldValue, newValue) { if (name === 'my-attribute') { console.log( `Value of my-attribute changed from ${oldValue} to ${newValue}` ) // You can perform some action based on the new value here } } } customElements.define('my-component', MyComponent)