Answer the question
In order to leave comments, you need to log in
Why does selection disappear in input after element.select()?
Hello!
Faced with the need to highlight the value in the text field on focus.
I wrote a simple directive for this:
function inputFocusDirective() {
return {
restrict: "A",
link: function (scope, element, attrs) {
element.on("focus", function () {
scope.$apply(function() {
element.select();
});
});
}
}
}
<input type="text" onfocus="this.select()">
Answer the question
In order to leave comments, you need to log in
Try this solution
<input onClick="this.setSelectionRange(0, this.value.length)" value="Sample Text" />
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question