It has nothing to do with jQuery, it's how the events are defined in javaScript.
A click
event is a mousedown
followed by a mouseup
on the same element.
In other words, the mousedown
event fires first when the mouse button is pressed, then the mouseup
event fires when the button is released, and if they both fired on the same element, the click
event fires.
You can easily test this -> http://jsfiddle.net/4EUPm/
EDIT:
Edit #1 Lots of these responses are touching on my question a bit, but
what i would like to know is if .click will wait for the .mouseDown to
completely run through before the code for .click starts running? As
in, its guaranteed to do so, or if i have to write logic to ensure
that.
Javascript has only one thread, so two functions can not execute at the same time, with a few exceptions, like asynchronous methods.
Also, a click
waits for both the mousedown
and mouseup
, and then checks both of those to see that the target was the same element, so yes, a click
event handler can not fire until after the mousedown
and the mouseup
event has fired, it's just not possible.
Wether or not every piece of code inside the mousedown
event handler finishes before the click
event handler is fired, is impossible to answer without knowing exactly what's inside those event handlers, but generally all the code in the mousedown
event handler will finish before the code in the click
event handler starts, unless there's async behaviour or other strangeness going on.