Javascript: cross browser solution for selecting all text inside a textbox on focus - Javascript jQuery

Javascript examples for jQuery:Selector

Description

Javascript: cross browser solution for selecting all text inside a textbox on focus

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.6.2.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//  w w  w . j  av a 2  s .c o m
$('input[type="text"]').live('focus', function() {
    var inp = this;
    setTimeout(function() {
        inp.select();
    }, 1);
});
    });

      </script> 
 </head> 
 <body> 
  <input type="text" value="click me to autoselect">  
 </body>
</html>

Related Tutorials