jquery / jquery/api.jquery.com
Should `.trigger()` more clearly indicate that it does not invoke event listeners created outside of jQuery?
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 325
- Forks
- 260
- PR merge metrics
- No merged PRs in 30d
Description
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).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the .trigger() documentation at https://api.jquery.com/trigger/ and review the existing explanation of handlers attached with .on() and shortcut methods. Update the page to explicitly distinguish those handlers from listeners added with EventTarget.addEventListener(), then verify that the wording clearly explains the difference from dispatchEvent().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jquery
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100