Opened 10 years ago
Closed 10 years ago
#12734 closed feature (wontfix)
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.
Change History (12)
comment:1 Changed 10 years ago by
Component: | unfiled → event |
---|---|
Keywords: | 1.9-discuss added |
Priority: | undecided → low |
Status: | new → open |
Version: | git → 1.8.2 |
comment:2 Changed 10 years ago by
comment:3 Changed 10 years ago by
What would the return value be for .triggerHandler()
when triggering multiple events?
Also, what is the use case for triggering two different events?
comment:4 Changed 10 years ago by
@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
comment:5 Changed 10 years ago by
I understand what the code does, I don't understand when you would want to trigger two events at the same time.
comment:6 Changed 10 years ago by
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)
comment:7 Changed 10 years ago by
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.
comment:8 Changed 10 years ago by
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.
comment:9 Changed 10 years ago by
+1, I don't see a use for it, but the implementation should be safe and pretty tiny.
comment:10 Changed 10 years ago by
-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.
comment:12 Changed 10 years ago by
Resolution: | → wontfix |
---|---|
Status: | open → closed |
+1, why not