Lesson 11 of 55
javascriptEvent Propagation – Capturing, Bubbling & `stopPropagation`
10 mins
Course progress20%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 11 of 55
javascript10 mins
Keep these ideas in mind as you work through the lesson.
When an event occurs it travels through three phases:
window down to the target.window.You can control the phase with the third argument of addEventListener:
element.addEventListener('click', handler, true); // capture
e.stopPropagation() to halt further propagation, or e.stopImmediatePropagation() to also stop other listeners on the same element.div.addEventListener('click', e => {
e.stopPropagation();
console.log('Div clicked – event will not reach body');
});