Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  62] [ 7]  / answers: 1 / hits: 22435  / 11 Years ago, mon, july 1, 2013, 12:00:00

In the following code:



$(document).keypress(function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 40) {
alert(down pressed);
} else if (code == 38) {
alert(up pressed);
}
});


I'm trying to detect if the down key or up key is pressed. Why isn't it working?



Fiddle
http://jsfiddle.net/K9uDn/10/



I'm in chrome


More From » jquery

 Answers
15

Use keydown instead of keypress, some browsers does not fire keypress when an special key (like arrows) are pressed


[#77275] Saturday, June 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kinsley

Total Points: 352
Total Questions: 84
Total Answers: 94

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
;