Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardHTMLobservedAttributesSingle-choice MCQ

An element observes `value`. The constructor body does `this.setAttribute('value', 'x')`. The element is created via `document.createElement('my-el')`. Does `attributeChangedCallback` fire for that constructor-time `setAttribute`, and why?

class MyEl extends HTMLElement { static get observedAttributes() { return ['value']; } constructor() { super(); this.setAttribute('value', 'x'); } attributeChangedCallback(n, o, v) { console.log('changed', n, o, v); } } customElements.define('my-el', MyEl); const el = document.createElement('my-el');