Course contentsShow
← Web Development
Lesson 721 of 2,98213. DOM EventsFree lesson

Event Capturing Phase

Understanding the less-common capturing phase where events travel down to the target element first.

Event Capturing Phase

You'll learn how events can travel from the top of the DOM tree down to the target element before bubbling back up.

What Is Event Capturing?

When an event occurs on an element, it doesn't instantly start at that element. Instead, the event makes a journey through the DOM tree in two phases. You've already learned about bubbling (where the event travels upward from the target). But before bubbling happens, there's capturing.

Event capturing (also called the "capture phase") is when the event travels down through the DOM tree, starting from the document and moving through each ancestor until it reaches the actual target element.

Think of it like a diving expedition: the event dives down from the surface (document) through each level of water (parent elements) until it reaches the ocean floor (target element), then bubbles back up to the surface.

How to Use Capturing

By default, addEventListener() listens during the bubbling phase. To listen during the capturing phase instead, pass true as the third argument:

element.addEventListener('click', handler, true);
// or more explicitly:
element.addEventListener('click', handler, { capture: true });

The event will trigger on this element during its journey down to the target, before the target's own handlers run.

When Would You Use It?

Capturing is less common than bubbling but useful when you need to intercept events before they reach their target—for example, implementing global event filters or logging systems.

Key Takeaway: The capturing phase lets you handle events as they travel down the DOM tree toward the target element, by setting the third parameter of addEventListener() to true.