I have this easy code :
<a href="#" id="link1">Link1</a>
<a href="#" id="link2">Link2</a>
$('#link1').click(function () {
alert("First");
});
$('#link2').click(function () {
alert("Second");
});
in a “remote” possiblity that a user click on Link1 (first) and than on Link2, with a difference of 0,000000001 ms (I know, is it impossible in the reality, but is just to know), is it possible that the alert of #link2 start before the alert of #link1?
And if yes, what’s the solution to block handler of #link2 till the action of #link1 is it not finished?
No. If the clicks actually happen in that order, the events will be triggered in that order.
JavaScript is single threaded, and the event systems are synchronous. This guarantees that the synchronous portion of the first click must complete before the second click event is allowed.
If asynchronous code is introduced into the handler for the first click, then the first click will still begin first, but the second click could start if it takes place before the first click’s asynchronous code runs.
To simulate a super fast sequence of clicks, just have the code trigger the events.