After calling trigger on a browser event, how can I call a function when it has finished?
I'm calling trigger on a checkbox to flip its state. Once this is done I need to call a function. Part of the function counts the number of boxes checked so this function can only be called after the checkbox has flipped.
$('input',this).trigger('click');
// What do I do to call afterTrigger() when 'input' click event has fini开发者_开发百科shed.
function afterTrigger(){
// ... calculation
}
You can call the function directly after the trigger event.
$('input',this).trigger('click');
afterTriger();
Calls to .trigger('foo')
are synchronous, so you can just call your function.
$(this).find('input').trigger('click');
afterTrigger();
精彩评论