I want to capture the TAB keypress, cancel the default action and call my own javascript function.
Above shown methods did not work for me, may be i am using bit old jquery, then finally the below shown code snippet works for - posting just in case somebody in my same position
$('#textBox').live('keydown', function(e) {
if (e.keyCode == 9) {
e.preventDefault();
alert('tab');
}
});
Working example in jQuery 1.9:
$('body').on('keydown', '#textbox', function(e) {
if (e.which == 9) {
e.preventDefault();
// do your code
}
});
You can capture an event tab using this JQuery API.
$( "#yourInputTextId" ).keydown(function(evt) {
if(evt.key === "Tab")
//call your function
});