Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to figure out if there is a bug in jQuery or if it's something I'm doing

$(document).keydown(function (event)
    {
    alert(event.which);
    });

For the semicolon key, ;, this gives 59 in Firefox and 186 in Chrome. However, from the jQuery reference page for the keydown event, it says

"While browsers use differing properties to store this information, jQuery normalizes the .which property so you can reliably use it to retrieve the key code. This code corresponds to a key on the keyboard, including codes for special keys such as arrows."

Am I missing something?

like image 661
Nick Avatar asked Oct 25 '11 20:10

Nick


1 Answers

The which property is a "one stop shop" for which key was pressed, allowing you to ignore the differences between the keyCode and charCode properties. That is the "normalization" that jQuery provides.

The difference in the value of which comes down to a difference between the way the various browsers supply the information - so you'll have to write code to handle the different values that come back. There are a few references to this behavior online.

like image 59
Sean Bright Avatar answered Sep 23 '22 04:09

Sean Bright