Side navigation
#12734 closed feature (wontfix)
Opened October 15, 2012 02:46PM UTC
Closed October 29, 2012 05:41PM UTC
jQuery#trigger, jQuery#triggerHandler trigger multiple events
Reported by: | markel | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | event | Version: | 1.8.2 |
Keywords: | 1.9-discuss | Cc: | |
Blocked by: | Blocking: |
Description
You can remove attributes like this –
elem.removeAttr("first second");
or add/remove classes –
elem.remove(add)Class("first second", fn);
and attach/detach events this way, but you can't trigger them like this –
elem.trigger("first second");
It would be useful if jQuery#trigger, jQuery#triggerHandler could do that, please consider this for jQuery 1.9.
Attachments (0)
Change History (12)
Changed October 15, 2012 02:47PM UTC by comment:1
component: | unfiled → event |
---|---|
keywords: | → 1.9-discuss |
priority: | undecided → low |
status: | new → open |
version: | git → 1.8.2 |
Changed October 15, 2012 02:51PM UTC by comment:2
+1, why not
Changed October 15, 2012 03:44PM UTC by comment:3
What would the return value be for .triggerHandler()
when triggering multiple events?
Also, what is the use case for triggering two different events?
Changed October 15, 2012 04:16PM UTC by comment:4
@scott.gonzalez
What would the return value be for .triggerHandler() when triggering multiple events?
it would return value of the last called function, consider this example –
http://jsfiddle.net/r9a9H/, for different events result should be the same, i included test for it (https://github.com/orkel/jquery/commit/7f39ebb36807624390e757deac049bf3215a4ed1#L1R1097) in the PR
Also, what is the use case for triggering two different events?
with this change this –
elem.trigger("first").trigger("second");
and this –
elem.trigger("first second");
should produce the same result
Changed October 15, 2012 11:55PM UTC by comment:5
I understand what the code does, I don't understand when you would want to trigger two events at the same time.
Changed October 16, 2012 07:07AM UTC by comment:6
when you would want to trigger two events at the same time.
Use case is the same like when you trigger all namespace events, like so – http://jsfiddle.net/MYMsk/
or when you trigger one event with couple functions attached on that event. This change would give
more flexibility (i, for one, would love to have this feature) and consistency (if you can attach couple events at once, it's only logical if you can trigger some events at once)
Changed October 16, 2012 12:16PM UTC by comment:7
Namespaced events are really about the person listening, not the person notifying. You still haven't provided an actual use case, you've just provided example of code that show what the code does. Please explain a specific situation in which you want two different events triggered at the same time.
Changed October 16, 2012 01:12PM UTC by comment:8
Namespaces events are "really" about what can be done with them, therefore they can "really" be used that way.
If you have some actions attached to dom element and you wanted them to happen simultaneously, this is self-explanatory, axiomatic. If this is not specific enough, you may consider it a feature without a use case.
Changed October 22, 2012 05:53PM UTC by comment:9
+1, I don't see a use for it, but the implementation should be safe and pretty tiny.
Changed October 23, 2012 06:42PM UTC by comment:10
-1, I'm worried about the phrase "happen simultaneously" as the catalyst for this. Even if we add this sugar, the triggered events will not actually happen "at the same time" or "simultaneously," and I don't think we should give the impression that somehow, they are.
Changed October 29, 2012 05:36PM UTC by comment:11
-1, Not that needed, easy to do other ways.
Changed October 29, 2012 05:41PM UTC by comment:12
resolution: | → wontfix |
---|---|
status: | open → closed |