Unbind specific callbacks
See original GitHub issueIf there are multiple callbacks bound to a given key, e.g.
Mousetrap.bind('a', callback1)
Mousetrap.bind('a', callback2)
then using unbind
nukes both of them. it’d be great to be able to unbind just one callback, e.g.
Mousetrap.unbind('a', callback2)
This seems like pretty common functionality – you can see it in jquery’s off
, and in the DOM’s removeEventListener
, etc.
I’m happy to write the feature and submit a pull request if this is something other people want too!
Issue Analytics
- State:
- Created 11 years ago
- Reactions:15
- Comments:12 (2 by maintainers)
Top Results From Across the Web
.unbind() | jQuery API Documentation
A string containing one or more DOM event types, such as "click" or "submit," or custom event names. handler. Type: Function( Event eventObject...
Read more >Bind / Unbind inside callback - jquery - Stack Overflow
What i'm trying to do is add the css for two div's... one that is a wrapper div which will slide out when...
Read more >jQuery unbind() Method - W3Schools
How to use the unbind() method to unbind a specific function from a specified event for an element. ... Specifies an event object...
Read more >Binding and unbinding of event handlers - plainJS
Binding and unbinding of event handlers. How to attach or detach a handler function to an event, such as click, focus, or submit....
Read more >Backbone.js
If no event is specified, callbacks for all events will be removed. ... by telling it to remove just the events it's listening...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve used a
Mousetrap
new instance as a namespace.But,
Mousetrap.trigger
doesn’t notify to all instances. (Mousetrap.trigger
is not a global)+1 This feature seems still necessary also.
Mousetrap actually doesn’t even allow binding of multiple callbacks right now. The second ‘a’ will overwrite the first one. So even before calling
unbind
,callback1
will never be called.I feel like having multiple callbacks tied to the same key would be strange. Can you think of a use case where you would want to do that?