I have some input fields that are pre-filled through jQuery. I'd like to grab the value of an input, check if it starts with "x" and if it does, select that x. (So that the user can quickly change the x by just typing something else).
I know there is a question like this here: Selecting Part of String inside an Input Box with jQuery
But it's a really old question and it doesn't really use jQuery!
So, how can I select the x in this input's value?
<input class="input" type="text" value="x*500*500" />
I tried:
var input = $('.input');
input.setSelectionRange(0, 2); // Highlights "X"
input.focus();
error: Uncaught TypeError: input.setSelectionRange is not a function
. Is setSelectionRange
deprecated?