How do you stop event bubbling in JavaScript?
Call event.stopPropagation() in the handler. This prevents the event from propagating further (both up and down). Note: this does not prevent other listeners on the same element; use event.stopImmediatePropagation() for that.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Event Bubbling, Capturing, and Delegation in JavaScript
When an event on a child element propagates up to its parents. A click on a button inside a div triggers the button's listener, then the div's listener, then the body's, up to the document. By default, listeners run in the bubbling phase.
The downward phase of event propagation, from the document down to the target's parent. Listen in the capturing phase with addEventListener(type, handler, true). By default, listeners run in the bubbling phase (false).
Adding one listener to a parent instead of many listeners to children. Use event.target to determine which child was clicked. This is memory-efficient and works for dynamically added children without needing new listeners.
Still have questions?
Browse all our FAQs or reach out to our support team
