views:

79

answers:

2

if I have

$("a#foo").click();
$("a#bar").click();
dostuff();

and both have click handlers attached which do different things..is it guaranteed that bar's click handler will only execute after foo's completes? or are they dispatched asyncronously

similarly..will dostuff() only execute after foo and bar's click handlers complete?

+1  A: 

It depends on what foo does (You could technically set up foo to fire events using setTimeout which could fire after the method completes), but yes bar should fire after foo completes.

Kevin
+1  A: 

The Javascript execution model in the browser is single threaded (by and large), so there is no asynchronous dispatch going on anywhere outside stuff like the HttpXmlRequest.

So the foo click() function will return before bar click() is called, which will return before doStuff() is called.

j-g-faustus