In my (javascript, jQuery) code, I use two ways to fire events
jQuery('body').trigger('crazy-trigger-event'); jQuery("body").get(0).dispatchEvent(new CustomEvent("crazy-dispatch-event"));
In this snippet:
http://jsfiddle.net/jts9jhbt/3/
I registered for custom events using both jQuery.on () and the DOM.addEventListener () methods.
Then I fire events using the jQuery.trigger () and DOM.dispatchEvent () methods.
It seems that listeners registered using .on () receive events fired in both directions.
But listeners registered in .addEventListener () receive only events fired using .dispatchEvent ().
My use case is that I have a combination of legacy code and jQuery code, and it seems to be safer to use .dispatchEvent () so that it is compatible with both.
So, are there some changes in the code that I can make so that listeners registered with .addEventListener () can receive events from .trigger ()?
source share