Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • 3
    This worked for me but had to include stopping the mouseup on the same inputs. Commented May 25, 2012 at 21:31
  • 9
    This did not work for me on either an iPad or an iPhone Commented Feb 12, 2014 at 16:01
  • 5
    This only worked for me if I triggered .focus() on the input before invoking input.setSelectionRange. If you're listening for the focus event on the input, remember to account for an infinite loop. Commented May 29, 2014 at 19:37
  • 10
    A gotcha that is worth mentioning: this will not work on textareas if they have the readonly attribute set. Commented Jun 23, 2014 at 18:15
  • 7
    I spent over an hour playing with various solutions. Calling setSelectionRange() in a focus handler works when you trigger .focus() programmatically, but when you manually tap into the text input on iOS, the selection does not happen. Suffice it to say, all you need to do is call setSelectionRange() within a setTimeout of 0 and it works as expected no matter what triggers the focus. Commented Apr 1, 2016 at 6:11