A concise answer is :
Whether it is a capturing phase or bubbling phase, DOM propagation is stopped on the first encounter of e.stopPropagation()
.
So in case 1 you have these elements on DOM:
el1.addEventListener('click', doSomething1, true);
el2.addEventListener('click', doSomething2, true); // Listener calls `e.stopPropagation()`
el3.addEventListener('click', doSomething3, true);
Note: On HTML page structure, el3
is a direct child of el2
. And el2
is a direct child of el1
.
We presume doSomething2
listener calls e.stopPropagation()
.
Clicking el3
, listeners run in order as:
- CAPTURING PHASE:
doSomething1
--> doSomething2
--> ❌ no any other listener is run(whether capturing or bubble phase) - so el3
listener is not run
- BUBBLING PHASE: ❌ Not even reachable
And in in case 2 you have these elements on DOM:
el1.addEventListener('click', doSomething1, true);
el2.addEventListener('click', doSomething2, false); // Listener calls `e.stopPropagation()`
el3.addEventListener('click', doSomething3, true);
Clicking el3
, listeners run in order as:
- CAPTURING PHASE:
doSomething1
--> doSomething3
(All capture phase listeners down the DOM tree upto the clicked el3
element have been run) - so el3
listener is run
- BUBBLING PHASE:
doSomething2
--> ❌ Any other bubble phase listener is not run