New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event handlers are not triggered across multiple instances #4815
Comments
Thanks for the report. jQuery doesn't rely on the Changing that would be a huge task that we'd most likely fail. We do plan an event subsystem refactor in 4.0 - see https://github.com/jquery/jquery/wiki/jQuery-4.0-Event-Design for some ideas - but I don't think we'll manage to change this part. |
Thanks for taking the time to look at this. Although a “wontfix” is not the answer I hoped for it is great to have one so quickly. So this means essentially: While it’s possible to use multiple instances of jQuery on the same page. Scripts using different versions can’t interact using jQuery’s event subsystem. From my PoV this makes having multiple instances of jQuery useless except for the most simple cases. Seems that we have to find a way around that somehow. 🤔 Maybe it would be good to mentioned that (rather prominently) in the docs about |
This doesn't just affect jQuery, native handlers will also not be called on jQuery As for documentation, please open an issue on https://github.com/jquery/api.jquery.com, ideally also prepare a PR with your proposed wording. All doc pages for jQuery APIs are in the |
jQuery has had this behavior since its inception in 2006, and during that time I can only remember maybe five or so reports of people being confused about it or wanting the feature. As @mgol says, the intent of the |
@dmethvin I’m not even sure I want this feature ;-) It was just unexpected. It was rather non-obvious and cost me quite some time to debug because of that. My use case:
So having part of your JS being able to use modern jQuery while other parts are still legacy is not a use-case. The compromise is likely to be to try and upgrade the legacy site to jQuery 2.2+ and downgrade the Parcel bundle accordingly to be able to use the global scoped jQuery. |
There is this sentence in the docs about |
This just means that e.g. calling |
I have now implemented a jQuery event bridge that makes sharing events across jQuery instances possible. |
Description
When I have multiple jQuery instances on the same page. Events triggered using
$.trigger()
with one instance don’t execute event handlers bound with$.on()
using another instance.Link to test case
https://jsbin.com/dawajojave/edit?html,js,output
In the test case there is a select. Two versions of jQuery are injected. Each of them binds to
$('select').on('change')
and updates the value in the first list. In the second list there is a button triggering a change in the select value using$('select').val('grapes').trigger('change')
for each version.Expected result
Both values in the first list are changed regardless of how the change was made to the select.
Actual result
While both jQuery instances get notified about changes to the select when it’s used directly they only get the change event from ”their own” buttons.
The text was updated successfully, but these errors were encountered: