Reputation: 1
I am trying to use a specific key to trigger an event within my page.
here is my js
$(".ryu").keydown(function() {
$(".ryu-still").hide();
$(".ryu-cool").show();
});
any idea on how to trigger the event using the "X" key
Upvotes: 0
Views: 65
Reputation: 186
you need to catch to see if the key being pressed is the right one
$(document).ready(function () {
$(".ryu").on('keydown',function(e){
if(e.which==88){ //88 = x key
$(".ryu-still").hide();
$(".ryu-cool").show();
}
});
});
jsfiddle or it didnt happen http://jsfiddle.net/u3uo7eLn/2/
Upvotes: 1
Reputation: 126
try this:
$('.ryu"').bind('keydown', function(e) {
if(e.keyCode== "x"){
//do something
$(".ryu-still").hide();
$(".ryu-cool").show();
}
});
good luck
Upvotes: 1