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 }));

Explanation

Set bubbles: true if ancestors should hear it. It is a lightweight way for web components and widgets to communicate without global state.

Further reading

Problem with a question

JavaScript · Middle · question 65

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz