adding event listener with custom callback? - Javascript DOM

Javascript examples for DOM:Event

Description

adding event listener with custom callback?

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <input type="text" id="game" value="type me"> 
      <script type="text/javascript">
function registerKeyListener(id, type, callback){
    document.getElementById(id).addEventListener(type, callback);
}
registerKeyListener("game", "keydown", move);
function move(){/*w w w  . j  a  v  a  2 s  .  co m*/
    console.log("move function called");
}

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

Related Tutorials