Display key code during pressing document - Javascript DOM

Javascript examples for DOM:Key Event

Description

Display key code during pressing document

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){// w  w w  .j a  v a2s.c  o m
document.addEventListener("keydown", keyDown, false);
function keyDown(e) {
    document.getElementById("key").innerHTML = e.keyCode;
}
    }

      </script> 
   </head> 
   <body> 
      <p id="key"></p>  
   </body>
</html>

Related Tutorials