JavaScript for WordPress Forums Vanilla JavaScript Event phases: bubblin', capturin' clarification Reply To: Event phases: bubblin', capturin' clarification

#10633
Vincent Maglione
Participant

Know what? My mental model of the event system was wrong. Reading the spec helped.

I was getting tripped up because I kept thinking the event listener on the event target determined the actual phase of the event—but now I understand that it does no such thing. (I also sorta thought the event object traveled from the event target, except in the case of capturing events, but that’s also wrong.)

If I’m understanding correctly (please correct me if I’m wrong): the event travels down and then up through the DOM tree no matter what’s listening, unless we use the preventDefault or stopPropagation methods.

That makes the listener order much clearer to me now. Event travels from window to event.target and back to window regardless of how it’s heard along the way. Listeners just execute callbacks when they hear ’em.

You made that clear in the video—I just misunderstood. Thank you for your patience!