I have an input text box with some text in it , onclick event I want to run a javascript function to select (highlight) all text that is in this box , how I can do that with jquery?
+1
A:
You can do this:
$('input').click(function() {
// the select() function on the DOM element will do what you want
this.select();
});
Of course, then you can't click on the element to select an arbitrary point in the input, so it might be better to fire that event on focus
instead of click
gnarf
2010-06-09 11:15:30
Is that gnarf like Pinky used to say on pinky and the brain?
Zoidberg
2010-06-09 11:20:30
@Zoidberg - Nope, that would be `narf` --- Although pronounced the same, `gnarf` is simply my last name backwards.
gnarf
2010-06-09 11:22:25
+5
A:
You may take a look at this article. (first result on google)
Darin Dimitrov
2010-06-09 11:15:49
+3
A:
No need for jQuery, this is simple with the DOM and works in all mainstream browsers:
input.onfocus = function() { this.select(); };
If you must do it with jQuery, there's very little difference:
$(input).focus(function() { this.select(); });
Tim Down
2010-06-09 11:21:52