Reputation: 18798
Why doesn't event.which
work in IE?
This my code, which works fine in Firefox and Chrome but not in IE.
$("#inputFeild").keypress(function(event){
alert(event.which);
});
#inputFeild
is a textarea.
Upvotes: 0
Views: 1135
Reputation: 630419
The keypress
event in particular is unreliable for the keycode, use the appropriate event for whatever you're doing...for example if you need the value, use keyup
instead:
$("#inputFeild").keyup(function(event){
alert(event.which);
});
The .keypress()
documentation notes a few of these differences:
Note that
keydown
andkeyup
provide a code indicating which key is pressed, whilekeypress
indicates which character was entered. For example, a lowercase "a" will be reported as 65 bykeydown
andkeyup
, but as 97 bykeypress
. An uppercase "A" is reported as 65 by all events. Because of this distinction, when catching special keystrokes such as arrow keys,.keydown()
or.keyup()
is a better choice.
Upvotes: 3