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

#10087
Vincent Maglione
Participant

Sorry to be unclear. I updated the Fiddle to make it a bit easier for me to visualize.

My question, more clearly (I hope), is this:

If I’ve set the .boxes to use a capturing listener, but left #content (the outermost element) as a bubbling listener, and then I click the innermost box, I expect the log to look like this:


#content heard event from b3 via Capturing // I expect this to be the first, since the event is traveling down the tree instead of up
b3 phase: Capturing
b3 phase: Capturing
b3 phase: At Target

But it happens the other way around. The .box elements react as expected, but #content still hears the event _last_, even though the event target is set to capturing. The log instead looks like this:


b3 phase: Capturing
b3 phase: Capturing
b3 phase: At Target
#content heard event from b3 via Bubbling // Instead it's last and its phase is 'bubbling'

That’s confusing to me. If the event is traveling down the tree since the listener is set to capture, why is #content still hearing it first?

I hope that makes more sense. Forgive me if I’m making this more complicated than it needs to be.

Thank you!

vm