0

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

2 Answers 2

1

try this:

 $('.ryu"').bind('keydown', function(e) { if(e.keyCode== "x"){ //do something $(".ryu-still").hide(); $(".ryu-cool").show(); } }); 

good luck

Sign up to request clarification or add additional context in comments.

Comments

1

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/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.