OnlineCBT Logo OnlineCBT
JavaScript Tutorial
JAVASCRIPT · LESSON 21

Event Propagation: Bubbling, Capturing, and Delegation

By Ratan Updated: 16 Oct 2026

Understand event bubbling up the DOM tree, stopPropagation(), and event delegation patterns.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

Follow an event through the document

For an event that bubbles, dispatch travels through a capture phase toward the target and then a bubbling phase back through ancestors. This lets a parent handle actions from many descendant controls with one listener.

Clicking the span still finds its button through closest. A later button added to the same list can use the existing parent listener. The containment check keeps the delegated action inside its intended component boundary.

Observe phase order

Register one parent listener with capture:true and another ordinary listener. Add a listener on the button. For a basic click, expect parent capture, button target handling, then parent bubbling. Not every event bubbles; choose an appropriate event or explicit strategy for that case.

Stopping propagation is not cancelling behavior

stopPropagation prevents further propagation along the path. It does not automatically prevent link navigation or form submission. preventDefault requests cancellation of a cancelable default action. stopImmediatePropagation also stops later listeners on the same target; use these controls carefully because unrelated components may rely on the event.

Delegation tradeoffs

Delegation is useful for dynamic lists but does not eliminate the need for validation. A data attribute is client-controlled. Opening a lesson or deleting a server record must still follow the application's permission rules.

Practice

  1. Add a third button after listener registration and confirm delegation works.
  2. Click a list area outside a button; no lesson action should occur.
  3. Log eventPhase and currentTarget in capture and bubbling handlers.
  4. Explain why preventing navigation differs from stopping the click from reaching a parent.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
पता संपर्क करें

+91 7877547686

ई-मेल

onlinecbtportal@gmail.com

हेल्पलाइन नंबर

+91 7877547686


डाउनलोड करने के लिए क्लिक करें
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat