Javascript Event Order

A typical problem that developers face is handling an event of same type, when the elements are nested and both of them implement the same event. Suppose you have an element (say element 2) inside another element (say element 1). Let’s say both element 1 and element 2 implement the onclick event. When the user clicks on element 2, since it is nested, should the onclick event of element 1 get triggered first and then of element 2 or vice versa? Since the elements are nested and using the same event both the element’s event handler methods are called. The question is which one first.

Here is a link to a blog article “Event Order” which explains the problem, and the solution to it. Thanks to my friend and colleague, Narayanan who sent me this link when we faced the problem handling such a situation while developing Jiffle.