m5vnaw
Last Updated: February 25, 2016
·
662
· andi1984

Selecting input content programmatically on iOS 4-6

A few days ago I worked on a project where I needed to select all the content on an input field. In most of the cases this can be done by using the

.select()

method. But at least on iOS 6 this didn't work at all. Then I found a StackOverflow Post where somebody posted the following two pure javascript lines of code.

document.getElementById("p1").selectionStart = 0
document.getElementById("p1").selectionEnd = 999

And this hack works perfectly! Maybe you will need these two lines somedays. I searched a lot to get the final answer...