Kiseo Simon Kang
Kiseo Simon Kang

Reputation: 1

specifc keydown to trigger an event

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

Answers (2)

B-rad
B-rad

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

Fabian De Leon
Fabian De Leon

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

Related Questions