jQuery: bind two events -
i have div called mydiv. how call 2 functions 1 after other when user clicks it?
$('#mydiv').click(function () { action1() // wait until finishes , call action2 });
action1
function in script that's loaded in master page , action2
small inline script function that's different in every page means can't call action2
action1
because name action2
different on every page.
if action1 , action2 aren't asynchonous, can do:
$('#mydiv').click(function () { action1(); action2() });
if asynchonous, can couple of things. callbacks:
action1 = function(callback) { //stuff callback(); } $('#mydiv').click(function () { action1(this) });
note you're not calling action2 when pass it. passing function.
you fire event action1 , tell action2 listen event (working memory here):
action1 = function(element) { //stuff $(element).trigger('action1_finished') } $('#mydiv').click(function () { action1(this) }).bind('action1_finished', action2)
Comments
Post a Comment