There are two HTML elements, one is div element, and the other is input element. Assume that the focus is at input element in the beginning. onclick event handler of div element and onblur event handler of input element are registered. If div element is clicked, input element will lose focus. Here comes the question:
Which event handler is fired first?
This is a question similar to that asked in reference , and also the question I had when I developed my web application.
There are good news and bad news for the quesiton:
- The bad news is, according to references  and , the firing order (precedence) of event handlers are not defined in the HTML spec and hence depends on browser implementations.
- The good news is that although onblur event handler is fired before onclick event handler, onmousedown event handler is fired before onblur event handler. So we can move onclick event handler to onmousedown event of div element, which achieves the same result we need.
- Firing order (precedence) of event handlers depends on browser implementation. No spec on this.
- Register event handler to onmousedown event instead of onclick event, if you want the event handler to be fired before onblur event handler.