I am working with jQuery in this when I try e.keyCode
For enter key like below
if (e.keyCode === 13) {
// my code
}
then it works with ie7 and all major browsers but not in ie10.
But when I use e.which
it runs in all major browsers.
What is the difference between e.keyCode
and e.which
?
key 13 keycode is for ENTER key.
e. which is not an event, which is a property of the event object, which most people label as e in their event handlers. It contains the key code of the key which was pressed to trigger the event (eg: keydown, keyup).
keyCode: Returns the Unicode value of a non-character key in a keypress event or any key in any other type of keyboard event. event. charCode: Returns the Unicode value of a character key pressed during a keypress event.
The event.which property normalizes event.keyCode and event.charCode. It is recommended to watch event.which for keyboard key input.
As per JQuery documentation
keyCode is standard JavaScript and of course not implemented in the same way by all browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With