JavaScript Event cancelBubble Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated
Instance property

What You’ll Learn

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

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.

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 replacementevent.stopPropagation().
  • Deprecated on MDN; available in Web Workers but still avoid it.

📝 Syntax

JavaScript
event.cancelBubble = true; // deprecated — prefer stopPropagation()

Value

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

🔄 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.

⚡ Quick Reference

GoalCode / note
Legacy stopevent.cancelBubble = true (deprecated)
Modern stopevent.stopPropagation()
Stop + skip same-target listenersevent.stopImmediatePropagation()
Set falseNo effect in later implementations (MDN)
MDN statusDeprecated

🔍 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

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
};
Try It Yourself

How It Works

Setting true asks the browser not to propagate further. Still works in many engines, but is deprecated.

Example 2 — Prefer stopPropagation()

Same goal with the supported API.

JavaScript
elem.addEventListener("click", (event) => {
  // Do cool things here
  event.stopPropagation();
});
Try It Yourself

How It Works

This is the form you should write and teach. Same outcome as legacy cancelBubble = true.

📈 Compare Behaviors

See a parent get blocked, and why false is a no-op.

Example 3 — Parent Does Not Hear the Event

Dispatch a bubbling click-like event and stop it on the child.

JavaScript
const parent = document.getElementById("parent");
const child = document.getElementById("child");
const log = [];

parent.addEventListener("ping", () => log.push("parent"));
child.addEventListener("ping", (e) => {
  log.push("child");
  e.cancelBubble = true; // prefer e.stopPropagation()
});

child.dispatchEvent(new Event("ping", { bubbles: true }));
console.log(log.join(" → ")); // "child"
Try It Yourself

How It Works

Without stopping, the log would be child → parent because the event bubbles.

Example 4 — Setting false Does Nothing

MDN: later implementations ignore cancelBubble = false.

JavaScript
child.addEventListener("ping", (e) => {
  e.cancelBubble = false; // no-op in modern engines
});

// Parent will still hear a bubbling ping
parent.addEventListener("ping", () => {
  console.log("parent still heard it");
});

child.dispatchEvent(new Event("ping", { bubbles: true }));
Try It Yourself

How It Works

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);
Try It Yourself

How It Works

Use the try-it lab to click both modes and confirm parents stay quiet either way—then keep only the modern path in production.

🚀 Common Use Cases

  • Reading and updating legacy onclick / IE-era handlers.
  • Teaching the difference between stopping bubble vs canceling defaults.
  • Migrating codebases from cancelBubble to stopPropagation.
  • Component boundaries that must own a click without notifying parents (use modern API).
  • Debugging why a parent listener never fires (someone stopped propagation).

🔧 How It Works

1

Event reaches a handler

Your listener runs on the target or an ancestor.

Dispatch
2

Stop requested

Legacy: cancelBubble = true. Modern: stopPropagation().

Stop
3

Propagation ends

Further capturing/bubbling along the path is skipped.

Effect
4

Prefer modern APIs

Ship stopPropagation(); treat cancelBubble as legacy-only.

📝 Notes

  • MDN: Deprecated — Deprecated banner shown before What You’ll Learn.
  • Not Experimental / Non-standard on MDN, but still avoid in new code.
  • Available in Web Workers (still deprecated).
  • Setting false is a no-op in later implementations.
  • Related learning: bubbles, cancelable, Event(), addEventListener(), JavaScript hub.

Browser Support (Deprecated)

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.

Legacy Deprecated
Google Chrome Supported (legacy)
Legacy
Mozilla Firefox Supported (legacy)
Legacy
Apple Safari Supported (legacy)
Legacy
Microsoft Edge Supported (legacy)
Legacy
Opera Supported (legacy)
Legacy
Internet Explorer Historic support
Legacy
cancelBubble Deprecated

Bottom line: Recognize cancelBubble in old code, then replace with stopPropagation(). Do not teach cancelBubble as the primary API.

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().

Continue with composed, bubbles, cancelable, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use event.stopPropagation() in new code
  • Replace cancelBubble = true during refactors
  • Prefer addEventListener over onclick =
  • Know cancelable / preventDefault are separate
  • Document why a component stops propagation

❌ Don’t

  • Start new features with cancelBubble
  • Expect cancelBubble = false to resume bubbling
  • Confuse stopping bubble with canceling defaults
  • Stop propagation casually—it breaks delegation
  • Assume every engine will keep the legacy property forever

Key Takeaways

Knowledge Unlocked

Five things to remember about cancelBubble

Deprecated stop flag—migrate to stopPropagation.

5
Core concepts
🛑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().

Next: composed

Learn when events leave the shadow DOM boundary.

composed →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful