In JavaScript, how to handle Tabulation key press?
To handle the Tab key press event in JavaScript, use the following code:
document.querySelector('body').addEventListener('keydown', function(event)
{
// Get key code
var code = event.keyCode || event.which;
// Check if the key pressed is Tab (code = 9)
if (code === 9) {
// Keep the following line to prevent the default behavior of the Tab key
event.preventDefault();
// The tab key has been pressed
// Do some awesome stuff here
//...
}
});
To handle the Tab key press event in JavaScript, use the following code:
document.querySelector('body').addEventListener('keydown', function(event)
{
// Get key code
var code = event.keyCode || event.which;
// Check if the key pressed is Tab (code = 9)
if (code === 9) {
// Keep the following line to prevent the default behavior of the Tab key
event.preventDefault();
// The tab key has been pressed
// Do some awesome stuff here
//...
}
});
# | ID | Query | URL | Count |
---|