Adam
Adam

Reputation: 9449

jQuery @ Keypress detection in Firefox

I have a simple jquery a keypress code that detects when the user types the @ key. The problem: Works great in webkit (Chrome/Safari) but does absolutely nothing in FF.

The JS fiddle: http://jsfiddle.net/cUzzt/

The code:

$(document).ready(function(){
    $(document).keypress(function(e) {
          if(e.keyCode == 64) { //@ Symbol
              alert("You pressed the @ key");
          }
    });
});

Upvotes: 2

Views: 2467

Answers (1)

glortho
glortho

Reputation: 13200

You want charCode:

$(document).ready(function(){
    $(document).keypress(function(e) {
          if(e.charCode == 64) { //@ Symbol
              alert("You pressed the @ key");
          }
    });
});

Upvotes: 7

Related Questions