Alex Rivera | Logout

Unbind special keypress event

Asked 2011-09-21T13:56:48.310
13

I've got a question regarding jQuery keypress events. I've got the following (working) code:

$(document).bind('keypress', function(event) {

    if ($('#myDiv').is(':visible')) {

        if (event.which == 102) {
            // ...do something...
        }

    }
    else {
        if (event.which == 102) {
            return;
        }
    }

});

I always "unbind" the event with binding another "over" it. I know that I can unbind it with .unbind('keypress') but I got more keypress events and when i unbind this with $(document).unbind('keypress') all my events get lost.

Can I do something like "keypress.102" to only unbind this particular "key" or how can this be done?!

Edit
Report

1 Answer

1
answered 2011-09-21T13:58:02.853

Your Answer