Nikita Fedyashev
Nikita Fedyashev

Reputation: 19003

Unbind keypress handler for specific combination only

I have 2 keydown handlers:

$(document).bind('keydown', function(e) {
   if (e.keyCode == 75) {
       // handler1 strategy
   } else if (e.keyCode == 78) {
       // handler2 strategy
   }

});

How can I unbind one handler without affecting all the other keydown handlers?

updated.

Upvotes: 1

Views: 727

Answers (1)

Anurag
Anurag

Reputation: 141879

You could create a plugin that maintains a map of key combinations, and associated functions. Whenever it sees a keydown event, it calls each matching function. Removal of an existing handler will be easy too.

Upvotes: 1

Related Questions