I am looking for a way to dispatch an event from my jQuery plugin so that it can have multiple listeners for this event. I have a plugin setup so that it returns a link to itself, so that later I can add listeners via public methods.
The only examples I've seen so far have one event handler, for example:
$.fn.foo = function( options ) {
...
options.eventHandler();
}
$('#bar').foo({ eventHandler: myEventHandler })
I am the only option that I am going to do, it just has an array of registered event handlers and I call each of them, or I do not see a better alternative.
source
share