Keydown + keyup events for specific keys - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:keyup

Description

Keydown + keyup events for specific keys

Demo Code

ResultView the demo in separate window


<html>
   <head> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
   </head> 
   <body> 
      <script>
$(document).ready(function () {
    $('body').on('keydown keyup',function(e){
      var color = e.type=="keydown" ? 'red' : 'white' ;
      if(e.which==82){// w w  w .  jav  a 2s. c  o  m
          $(this).css({background: color});
      }
    });
});

      </script>  
   </body>
</html>

Related Tutorials