5

Let's say i have this input:

  <li><input type="text" id="elementHeight" class="form-control" placeholder="Height"> </li>

and i want to ''Select All'' in the input field when the user clicks on it.

nicholaswmin
  • 19,740
  • 13
  • 80
  • 155

3 Answers3

10

From a similar question, I got an answer I prefer.

<input type="text" onfocus="this.select();" onmouseup="return false;" />

Source: https://stackoverflow.com/a/480756/989227

Community
  • 1
  • 1
santiaago
  • 578
  • 8
  • 19
7
$('input').click(function () {
    this.select();
});
Dawid Rusnak
  • 367
  • 2
  • 12
2

when the field is focused ,clicked

$("#elementHeight").focus(function(){
    this.select();
});
Reza Saberi
  • 7,002
  • 9
  • 45
  • 74