Historically there are two models of behavior.
Netscape said that the event on element1 takes place first. This is called event capturing.
Microsoft maintained that the event on element2 takes precedence. This is called event bubbling.
Now you can decide which one (top to bottom or bottom to top) to use by setting|unsetting the last parameter of AddEventListener:
element1.addEventListener('click',doSomething2,true);
element2.addEventListener('click',doSomething,false);
If the last argument is true the event handler is set for the capturing phase, if it is false the event handler is set for the bubbling phase.
Here everything is explained perfectly.