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.
jQuery | keypress() The keypress() method in jQuery triggers the keypress event whenever browser registers a keyboard input. So, Using keypress() method it can be detected if any key is pressed or not.
The change event occurs if the value has been changed when the element loses focus. The keypress event occurs every time you press down and release a (non control) key.
jQuery keyup() Method The order of events related to the keyup event: keydown - The key is on its way down. keypress - The key is pressed down. keyup - The key is released.
Try it with .keyCode instead of .which:
$('input').live('keypress', function (e) {
if ( e.keyCode == 9 ){
alert( 'Tab pressed' );
}
});
Seem to work ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With