Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are jQuery events blocking

Are jQuery events blocking?

For example does calling the following method return immediately?

$("body").trigger("myEventName", myValue);

My testing seems to suggest they are. If this is correct does this mean I can return values from my custom events?

var myResult = $("body").trigger("myEventName", myValue);

Clearly this doesnt work as this returns the jQuery object. So can values be returned?

like image 771
Maxim Gershkovich Avatar asked Jun 20 '26 22:06

Maxim Gershkovich


1 Answers

You can use the .triggerHandler() method for this, it returns whatever the last event handler for that event on that selector returns (instead of a jQuery object for chaining), just use it like this:

var myResult = $("body").triggerHandler("myEventName", myValue);

You can give it a try here.

Check out the documentation page for the list of differences from .trigger().

like image 199
Nick Craver Avatar answered Jun 22 '26 10:06

Nick Craver