I have an input on that I want it to have focus and the text is already selected.
Focus I'm doing this:
$(".autofocus").trigger('focus');
The problem is that the text is not selected. Does anyone know how to do this?
I have an input on that I want it to have focus and the text is already selected.
Focus I'm doing this:
$(".autofocus").trigger('focus');
The problem is that the text is not selected. Does anyone know how to do this?
Place this code before the trigger code:
$(".autofocus").on("focus", function () {
$(this).select();
});
.on()
is currently unnecessary, it would suffice ( as documentation ) before .trigger()
the following code:
$(".autofocus").focus(function () {
$(this).select();
});
You can still perform directly on the element:
<input class="autofocus" type="text" onfocus="this.select();" onmouseup="return false;" />