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();
});
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With