Question #17   Submitted by Answiki on 04/29/2020 at 07:23:54 PM UTC

With jQuery, how to trigger event when the tabulation key is pressed?

Answer   Submitted by Answiki on 04/29/2020 at 07:12:32 PM UTC

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.

5 events in history
Question by Answiki 04/29/2020 at 07:23:54 PM
With jQuery, how to trigger event when the tabulation key is pressed?
Question by Answiki 04/29/2020 at 07:23:40 PM
With jQuery, how to trigger event on tabulation key?
Answer by Answiki on 04/29/2020 at 07:12:32 PM

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.

Answer by Answiki on 04/29/2020 at 07:12:19 PM

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.

Question by Answiki 04/29/2020 at 07:07:42 PM
With jQuery, how to trigger event on tab key?
# ID Query URL Count

Icons proudly provided by Friconix.