Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between e.keyCode and e.which? [duplicate]

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?

like image 789
Rituraj ratan Avatar asked Oct 08 '13 13:10

Rituraj ratan


People also ask

What is e keyCode === 13?

key 13 keycode is for ENTER key.

What is e Which?

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).

What is the difference between keyCode and charCode?

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.


1 Answers

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.

like image 70
mucio Avatar answered Oct 25 '22 09:10

mucio