Javascript: onclick and onblur priority issues

Imagine you have search input field which also opens a suggest container as soon as you begin to type. Also imagine you want the suggest container to vanish as soon as you leave the search input field. You put an onblur() event on your search input field. Now you also want to click on a value of the suggest container to execute a search. The problem now is, if you use an onclick() event for triggering the search via suggest container, the onclick() event will never be triggered. The onblur() of the search input is executed before the onclick() of the suggest container. To solve this issue just swap your onclick() with a onmousedown() event.  That solution let’s the browser automatically re-order the priorities of these event handlers.

Juni 15th, 2018