Javascript examples for DOM:Event
adding event listener with custom callback?
<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>