api.jquery.com icon indicating copy to clipboard operation
api.jquery.com copied to clipboard

Should `.trigger()` more clearly indicate that it does not invoke event listeners created outside of jQuery?

Open NReilingh opened this issue 4 years ago • 1 comments

I have been using jQuery for about 9 years, and only just today did I realize that $('#element').trigger('change'); is not equivalent to $('#element')[0].dispatchEvent(new Event('change'));.

On a careful reading of https://api.jquery.com/trigger/, it does indicate:

Any event handlers attached with .on() or one of its shortcut methods are triggered...

However, I wonder if there should be a more explicit callout that listeners for event types added via EventTarget.addEventListener() are not invoked.

I believe I had my incorrect expectation because I did not realized there was a semantic difference between a DOM EventListener and a jQuery event handler, and because I was already used to using jQuery as a sort of friendly, cross-browser interface for other Web APIs (Noting that new Event() never received support in IE, for example).

NReilingh avatar May 26 '21 20:05 NReilingh

This Learn article has some useful information, but I never came across it before finding a link to it in a different issue.

NReilingh avatar May 26 '21 21:05 NReilingh