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 |
|---|---|---|---|---|
| 0 | 13516 | alphons | https://en.ans.wiki/52/in-javascript-how-to-handle-tabulation-key-press | 1 |
| 1 | 12193 | en | https://en.ans.wiki/52/in-javascript-how-to-handle-tabulation-key-press | 7 |