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
  • 21,686
  • 15
  • 91
  • 167

4 Answers4

11

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
  • 608
  • 9
  • 19
8
$('input').click(function () {
    this.select();
});
Dawid Rusnak
  • 527
  • 3
  • 13
2

when the field is focused ,clicked

$("#elementHeight").focus(function(){
    this.select();
});
M Reza Saberi
  • 7,134
  • 9
  • 47
  • 76
0

As of Bootstrap 5, there's user-select-all, but it wasn't working for inputs so I added this to my script and it works like a charm:

$(".user-select-all").focus(function () {
   $(this).select();
});

Bootstrap 5 doc

Justin
  • 21
  • 6