Pre-recorded question

Question #58
In JavaScript, how to handle Tab key press?
Answer

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
		//...
	}
});

3 events in history
Question by Alphonsio 06/06/2020 at 03:44:58 PM
In JavaScript, how to handle Tabulation key press?
Answer by Alphonsio 06/06/2020 at 03:44:34 PM

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
		//...
	}
});

Question by Alphonsio 06/06/2020 at 03:40:34 PM
In JavaScript, how to handle Tab key press?
# ID Query URL Count

Icons proudly provided by Friconix.