The cancelBubble property is a deprecated boolean on Event. Setting it to true before returning from a handler stops further propagation. Learn what it did, why it is deprecated, how it compares to stopPropagation(), and how to migrate—with five examples and try-it labs.
01
Kind
Instance property
02
Type
boolean
03
Means
Stop propagation?
04
Prefer
stopPropagation()
05
Workers
Yes (still deprecated)
06
Status
Deprecated
Fundamentals
Introduction
Older scripts sometimes wrote event.cancelBubble = true to keep an event from continuing through the DOM. That idea still matters; the modern API for it is event.stopPropagation().
You may still see cancelBubble in legacy handlers (especially old onclick = assignments). Understand it so you can replace it cleanly—do not copy it into new projects.
💡
Beginner tip
Stopping propagation is not the same as canceling the default action. Use stopPropagation() to stop tree travel; use preventDefault() when cancelable is true to block the browser default.
Concept
Understanding Event.cancelBubble
An instance property (deprecated) that historically answered: “Should this event stop propagating further?”
Value — boolean; true means do not propagate further.
Write true — stops further propagation (legacy behavior).
Write false — does nothing in later implementations (MDN).
Modern replacement — event.stopPropagation().
Deprecated on MDN; available in Web Workers but still avoid it.
A boolean. The value true means the event must not be propagated further.
Preferred modern form
JavaScript
elem.addEventListener("click", (event) => {
// Do cool things here
event.stopPropagation();
});
Compare
⚖️ cancelBubble vs Related Ideas
Idea
Meaning
cancelBubble = true
Deprecated way to stop further propagation
stopPropagation()
Modern API to stop capturing/bubbling
stopImmediatePropagation()
Also skip other listeners on the same target
event.bubbles
Does this event bubble at all? (read-only)
event.cancelable
Can preventDefault() block the default?
Migration
🔄 Migrate to stopPropagation()
JavaScript
// Legacy (avoid in new code):
elem.onclick = (event) => {
event.cancelBubble = true;
};
// Modern replacement:
elem.addEventListener("click", (event) => {
event.stopPropagation();
});
Behavior goal is the same: ancestors should not see the event after your handler. Prefer addEventListener so you can register multiple listeners and remove them cleanly.
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Legacy stop
event.cancelBubble = true (deprecated)
Modern stop
event.stopPropagation()
Stop + skip same-target listeners
event.stopImmediatePropagation()
Set false
No effect in later implementations (MDN)
MDN status
Deprecated
Snapshot
🔍 At a Glance
Four facts to remember about Event.cancelBubble.
Type
boolean
Writable (legacy)
true means
stop
No further propagate
Prefer
stopPropagation
Modern API
Status
deprecated
Avoid in new code
Hands-On
Examples Gallery
Examples follow MDN Event: cancelBubble and show the modern replacement. Prefer stopPropagation() in real apps.
📚 Getting Started
Legacy pattern and the modern replacement.
Example 1 — Legacy cancelBubble = true (MDN)
MDN-style handler that sets the deprecated flag.
JavaScript
elem.onclick = (event) => {
// Do cool things here
event.cancelBubble = true; // deprecated
};
Only true (or stopPropagation()) stops travel. Writing false does not “resume” bubbling.
Example 5 — Side-by-Side Migration
Toggle between legacy and modern stop styles in one demo.
JavaScript
function stopLegacy(e) {
e.cancelBubble = true;
}
function stopModern(e) {
e.stopPropagation();
}
// Both prevent the parent from hearing a bubbling "ping"
child.addEventListener("ping", useModern ? stopModern : stopLegacy);
Event.cancelBubble is marked Deprecated on MDN. Logos use the shared browser-image-sprite.png sprite from this project. Engines may still support it for compatibility—prefer stopPropagation() everywhere.
✓ Deprecated
Event.cancelBubble
Legacy boolean to stop further event propagation. Use Event.stopPropagation() instead.
LegacyDeprecated
Google ChromeSupported (legacy)
Legacy
Mozilla FirefoxSupported (legacy)
Legacy
Apple SafariSupported (legacy)
Legacy
Microsoft EdgeSupported (legacy)
Legacy
OperaSupported (legacy)
Legacy
Internet ExplorerHistoric support
Legacy
cancelBubbleDeprecated
Bottom line: Recognize cancelBubble in old code, then replace with stopPropagation(). Do not teach cancelBubble as the primary API.
Wrap Up
Conclusion
Event.cancelBubble is a deprecated way to stop further propagation by setting the flag to true. Learn it for legacy code, then standardize on event.stopPropagation().
Assume every engine will keep the legacy property forever
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about cancelBubble
Deprecated stop flag—migrate to stopPropagation.
5
Core concepts
⚠️01
Deprecated
avoid new use
Status
🛑02
true
stop further travel
Meaning
❌03
false
usually a no-op
MDN
✅04
Prefer
stopPropagation()
Modern
🔄05
Migrate
legacy → modern
Practice
❓ Frequently Asked Questions
It is a deprecated boolean property on Event. Setting it to true before returning from a handler stops further propagation of the event. Prefer Event.stopPropagation() in new code.
MDN marks Event.cancelBubble as Deprecated. It is not Experimental or Non-standard on MDN, but you should avoid it in new projects and migrate legacy code to stopPropagation().
Call event.stopPropagation() to stop further capturing and bubbling. Use event.stopImmediatePropagation() if you also need to skip remaining listeners on the same target.
MDN notes that in later implementations, setting cancelBubble to false does nothing. Only setting true was meaningful historically for stopping propagation.
No. cancelable says whether preventDefault() can block the default action. cancelBubble (legacy) tried to stop propagation. They solve different problems.
Yes. MDN notes Event.cancelBubble is available in Web Workers, but it remains deprecated there as well—prefer stopPropagation().
Did you know?
The name cancelBubble comes from an older Internet Explorer model of event bubbling. The DOM standard kept the property for compatibility, but documents it as deprecated in favor of stopPropagation().