People say UA sniffing is bad. So I'm trying to do a feature detection for HTMLInputElement.select()
.
My reason is that, on iOS mobile devices, the function is supported, but it does not actually select text. I want to detect this so that I can use HTMLInputElement.setSelectionRange()
instead.
I tried this:
function checkInputSelectWorks() {
var testStr = "test";
var input = document.createElement("input");
input.value = testStr;
input.select();
return input.selectionEnd == testStr.length;
}
I thought this would be sufficient, but it seems that selectionEnd
is set to testStr.length
even before calling select()
. How should I go about doing this?
No jQuery, please. It shouldn't be necessary.
EDIT: Adding the input element to the DOM did not help. input.SelectionEnd
becomes 0 when added to DOM, but it still gets updated after .select()
on iOS without actually selecting text.