jquery / jquery/api.jquery.com

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

Open
#1,191 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.