Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.select() function does not work on iOS device [duplicate]

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();
});
like image 504
user782104 Avatar asked Mar 05 '13 01:03

user782104


1 Answers

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);
like image 196
kennypu Avatar answered Nov 06 '22 01:11

kennypu