Use element focus() method to move cursor - Javascript DOM

Javascript examples for DOM:Element focus

Description

Use element focus() method to move cursor

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(){/*from ww  w.  ja  v a 2s  . co  m*/
document.getElementById('my_button').onclick = function() {
    document.getElementById('my_textbox').focus();
};
    }

      </script> 
   </head> 
   <body> 
      <input type="text" id="my_textbox" value="My Text"> 
      <button id="my_button">Focus</button>  
   </body>
</html>

Related Tutorials