xaero
xaero

Reputation: 99

Why is this JavaScript not working? Any ideas

Here is a Jsfiddle http://jsfiddle.net/EzLnH/.
If I change the function to:

$(document).bind('keypress', function(event) {
    if (event.which === 77 && event.shiftKey) {
        alert('You pressed ctrl+m');
    }
});​

It works but the function in jsfiddle does not.
Any Ideas?

Upvotes: 1

Views: 53

Answers (1)

mash
mash

Reputation: 15229

Chaniging it to $(document).on("keydown"... worked for me. You should be using .on now, .bind is deprecated in jQuery 1.8+. The issue was the "keypress" part though, modifier keys don't get picked up by a keypress event so it seems.

Here's the Fiddle

Upvotes: 1

Related Questions