I want to capture the TAB keypress, cancel the default action and call my own javascript function.
I want to capture the TAB keypress, cancel the default action and call my own javascript function.
Edit: Since your element is dynamically inserted, you have to use delegated on()
as in your example, but you should bind it to the keydown event, because as @Marc comments, in IE the keypress event doesn't capture non-character keys:
$("#parentOfTextbox").on('keydown', '#textbox', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
e.preventDefault();
// call custom function here
}
});
Check an example here.