9

I would like to make an input box that, when the user selects it, all the text in the box is selected. So I decided to use the select() function, which is what I would like to achieve. However, it works as I expected on desktop browsers, but not on Safari on the iPad. How to fix the problem? Thanks.

$('#input').click(function(e){
      $(this).select();
});
dda
  • 6,030
  • 2
  • 25
  • 34
user782104
  • 13,233
  • 55
  • 172
  • 312

1 Answers1

19

according to this SO question(Programmatically selecting text in an input field on iOS devices (mobile Safari)), it doesn't work in iOS, and you need to use the setSelectionRange() function. in your case, it would be something like this:

$(this).get(0).setSelectionRange(0,9999);
Community
  • 1
  • 1
kennypu
  • 5,950
  • 2
  • 22
  • 28