MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Event Bubbling & Capturing0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
4.1Event Listeners4.2Event Bubbling & Capturing4.3Keyboard & Mouse Events4.4Form Events and Validation
HomeTutorialsJavaScript for IntermediateEvent Bubbling & Capturing
Keyboard & Mouse Events

Event Bubbling & Capturing

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

DOM events do not simply trigger in isolation on a single element. When an action occurs, the event travels through a structured three-phase lifecycle known as the DOM Event Flow: the Capturing Phase, the Target Phase, and the Bubbling Phase.


1. The 3 Phases of Event Propagation

1 PHASE 1: CAPTURING (Downwards)
2 Window ───────────────┐
3 │ │
4 Document │
5 │ │
6 <html> │
7 │ │
8 <body> │
9 │ │
10 <div id="wrapper"> │
11 │ ▼
12 │ PHASE 2: TARGET
13 │ <button id="btn">Click Me</button>
14 │ ▲
15 │ │
16 PHASE 3: BUBBLING (Upwards)
  1. 1
    Capturing Phase (Trickling): The event starts at window and travels down through document, html, body, and parent containers until it reaches the target.
  2. 2
    Target Phase: The event reaches the originating element (event.target).
  3. 3
    Bubbling Phase: The event travels back upwards from the target through all ancestors until reaching window.
Default Behavior: By default, addEventListener() registers listeners for the Bubbling Phase unless explicitly specified otherwise.

2. Capturing in Practice

To listen during the Capturing Phase, pass { capture: true } or simply true as the third parameter:

1const wrapper = document.querySelector('#wrapper');
2const button = document.querySelector('#btn');
3 
4wrapper.addEventListener('click', () => {
5 console.log('1. Wrapper clicked (Capturing phase)');
6}, { capture: true });
7 
8button.addEventListener('click', () => {
9 console.log('2. Button clicked (Target/Bubbling phase)');
10});
11 
12wrapper.addEventListener('click', () => {
13 console.log('3. Wrapper clicked (Bubbling phase)');
14});

When the button is clicked, output order is:

  1. 1
    1. Wrapper clicked (Capturing phase)
  2. 2
    2. Button clicked (Target/Bubbling phase)
  3. 3
    3. Wrapper clicked (Bubbling phase)

3. Stopping Propagation: stopPropagation() & stopImmediatePropagation()

event.stopPropagation()

Prevents the event from travelling any further up (in bubbling) or down (in capturing) the DOM tree:

1const nestedModal = document.querySelector('.modal-content');
2 
3nestedModal.addEventListener('click', (e) => {
4 // Prevent click on modal content from closing the backdrop overlay
5 e.stopPropagation();
6 console.log('Clicked inside modal content');
7});

event.stopImmediatePropagation()

Not only halts bubbling to parent nodes, but also prevents other listeners on the very same element from firing:

1button.addEventListener('click', (e) => {
2 console.log('Primary handler');
3 e.stopImmediatePropagation();
4});
5 
6button.addEventListener('click', () => {
7 console.log('Secondary handler'); // NEVER EXECUTED!
8});

4. Event Delegation: The Power of Bubbling

Because events bubble up through parent nodes, you do not need to attach separate listeners to hundreds of child elements. Instead, attach a single listener to the parent element.

1 Container (Single Event Listener Here)
2 ├── [Button 1] (Click bubbles up)
3 ├── [Button 2] (Click bubbles up)
4 └── [Button N] (Click bubbles up)

High-Performance Example: Dynamic List Deletion

1const userList = document.querySelector('#user-list');
2 
3// Single listener handles all existing AND future delete buttons!
4userList.addEventListener('click', (e) => {
5 const deleteBtn = e.target.closest('.btn-delete');
6
7 // If the click did not occur inside or on a delete button, ignore
8 if (!deleteBtn || !userList.contains(deleteBtn)) return;
9 
10 const listItem = deleteBtn.closest('li');
11 const userId = listItem.dataset.userId;
12 
13 console.log(`Deleting user: ${userId}`);
14 listItem.remove();
15});

Benefits of Event Delegation:

  1. 1
    Low Memory Footprint: 1 listener instead of 1,000 listeners.
  2. 2
    Dynamic Elements: Automatically works for items added asynchronously later via API calls.
  3. 3
    No Memory Leaks: Removing items does not leave orphaned listeners.

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
In standard DOM event flow, in what order do the three phases execute?
Question 2
What is the main architectural benefit of Event Delegation?
Question 3
What is the effect of calling event.stopPropagation()?
Question 4
How do you configure an event listener to fire during the Capturing phase instead of the Bubbling phase?
Question 5
How does stopImmediatePropagation() differ from stopPropagation()?
Next Lesson

Keyboard & Mouse Events

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Event ListenersKeyboard & Mouse Events

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext