Back to results for “Design Patterns in Java”
JavaScript › DOM & Events

What is event bubbling?

Beginner

Answer

Event bubbling means an event fired on an element propagates upward through its ancestors in the DOM tree, triggering any matching event listeners on parents after the target element's own listeners run.
document.getElementById('parent').addEventListener('click', () => console.log('parent clicked'));
document.getElementById('child').addEventListener('click', () => console.log('child clicked'));
// clicking child logs 'child clicked' then 'parent clicked'
Real-world example A single click listener on a <ul> catching clicks from any <li> inside it, instead of attaching a listener to every item.

Common follow-ups: How do you stop an event from bubbling further?