JQuery event blocking

Are jQuery events blocked?

For example, calling the next method immediately?

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

My tests seem to suggest that they are. If this is correct, does this mean that I can return values ​​from my custom events?

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

Obviously this does not work, since it returns a jQuery object. So can values ​​be returned?

+3
source share
1 answer

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

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

You can try it here .

.trigger().

+4

Source: https://habr.com/ru/post/1775135/


All Articles