IPad does not select all text inside text input when pressed

Well, that seems to be a simple request, but I don't think so. I just want this to be the case when the html input [type = "text"] is focused (enabled in ios), all the text is selected (like any regular browser). I looked around and found a couple of suggestions, but nothing works - this is what I tried:

$('input[type="text"], textarea').focus(function() {
    $(this).setSelectionRange(0, 9999);
}).mouseup(function(e){
    e.preventDefault();
});

Also tried the following:

$('input[type="text"], textarea').focus(function() {
    $(this).select();
}).mouseup(function(e){
    e.preventDefault();
});

I read that the mouseup event on ios makes funky, but I'm not sure. Any ideas?

+3
source share
2 answers

I believe it should be

$('input[type="text"], textarea').focus(function() {
    this.select(); //no jquery wrapper
}).mouseup(function(e){
    e.preventDefault();
});
0
source

why not use the jQuery Mobile tap event:

$(document).ready(function() {
    $("input[type=text], textarea").on("tap", function() {
        this.select();
    }).vmouseup(function(e){
        e.preventDefault();
    })
});
+1
source

All Articles