With jQuery, how to trigger event on tabulation key?
In jQuery, you can trigger an event when the tabulation key is pressed with the following code :
// Trigger event when a key is pressed
$('#myID').on('keydown', function(event)
{
// Get key code
var code = event.keyCode || event.which;
// If the tabulation key is pressed, code = 9
if (code === 9) {
event.preventDefault();
// Do something, the tabulation key is down
}
})
The call of event.preventDefault();
prevents the default behavior of the browser on tabulation key (set focus to next element), it is optional.
In jQuery, you can trigger an event when the tabulation key is pressed with the following code :
// Trigger event when a key is pressed
$('#myID').on('keydown', function(event)
{
// Get key code
var code = event.keyCode || event.which;
// If the tabulation key is pressed, code = 9
if (code === 9) {
event.preventDefault();
// Do something, the tabulation key is down
}
})
The call of event.preventDefault();
prevents the default behavior of the browser on tabulation key (set focus to next element), it is optional.
In jQuery, you can trigger an event when the tabulation key is pressed with the following code :
// Trigger event when a key is pressed
$('#myID').on('keydown', function(event)
{
// Get key code
var code = event.keyCode || event.which;
// If the tabulation key is pressed, code = 9
if (code === 9) {
event.preventDefault();
// Do something, the tabulation key is down
}
})
The call of event.preventDefault();
prevent the default behavior of the browser on tabulation key (set focus to next element), it is optionnal.
# | ID | Query | URL | Count |
---|