HTML page react to down arrow key pressed keyboard event - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:keypress

Description

HTML page react to down arrow key pressed keyboard event

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.11.0.js"></script> 
  <script type="text/javascript">
$(document).on("keydown", function (e) {
    e.preventDefault();//from   w w  w. j av a  2  s  . com
    var code = e.which || e.keyCode;
    console.log(code)
    if (code == 40) {
        console.log("down arrow pressed")
    }
});

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

Related Tutorials