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?
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With