jQuery Form How to - Select all text in input element








Question

We would like to know how to select all text in input element.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.10.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from w ww.ja  v  a  2  s.co m-->
    $("#myinput").click(function(e){
        e.preventDefault();
        this.select();
    });
});
</script>
</head>
<body>
  <div>
    <input id="myinput" type="text" />
  </div>
</body>
</html>

The code above is rendered as follows: