Question

I need to capture a tab keypress event on some dynamic inputs, but the normal syntax using the keypress event doesn't seem to be catching the key code.

$('input').live('keypress', function (e) {
   if ( e.which == 9 )
       alert( 'Tab pressed' );
});

This seems to be catching 0 as the keypress when I go through the debugger in firebug no matter which key I press.

Was it helpful?

Solution

Try it with .keyCode instead of .which:

$('input').live('keypress', function (e) {
   if ( e.keyCode == 9 ){
       alert( 'Tab pressed' );
    }
});

Seem to work ;)

OTHER TIPS

Try listening for keyup or keydown instead of keypress (per this SO post)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top