Reputation: 95
I want to fire event globally and receive it anywhere in my application. Based on the event received, I want to perform some operations.
I have a multistep form when user click the next button, I want to trigger an event
function multiStep(){
$('.body').trigger('stepchanged');
}
Now I want to receive stepchanged in another function and perform some operations.
if (stepchanged){
//do something
}
How to receive the events? Thanks
Upvotes: 0
Views: 58
Reputation: 782785
You need an event handler that sets the variable.
`$(".body").on("stepchanged", function() {
stepchanged = true;
})`
Although there's not really any need for the event handler, unless it does other things. You can just set the global variable in multistep()
.
Upvotes: 1