JavaScript · Middle · Question 65 of 75
How do you notify other parts of the page about something with a DOM event?
el.dispatchEvent(new CustomEvent("cart:add", { detail: { id: 7 }, bubbles: true }));- ✓Correct answer: Dispatch a
CustomEventwith data indetail; listeners useaddEventListener - 2Call
el.click()with arguments - 3Custom events require a library
Explanation
Set bubbles: true if ancestors should hear it. It is a lightweight way for web components and widgets to communicate without global state.