if click OR key down - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

if click OR key down

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.4.2.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from www  .  j a v a 2  s .  c o m*/
function stuff(e) { console.log('Something happened'); }
$('input[type=button]').click(function(e) {
    stuff(e);
});
$(document).keydown(function(e) {
    if (e.keyCode == 39) { stuff(e); }
});
    });

      </script> 
 </head> 
 <body> 
  <input type="button" name="x" value="Button">  
 </body>
</html>

Related Tutorials