How can I highlight all the text within a textbox when it is clicked using jQuery?
I couldn't get that to work.
Ben Shelock
2009-07-24 02:10:59
+2
A:
This works for me in both FF and IE.
<input type="text" value="username" id="user" />
<script>
$("#user").click( function()
{
$("#user").focus();
$("#user").select();
});
</script>
Kane Wallmann
2009-07-24 02:15:02
+1
A:
$('textarea').click(function() { this.focus(); this.select(); });
That should work for all textarea's - switch the selector if need be.
I would probably go with class='autoselect'
and then $('.autoselect')
gnarf
2009-07-24 02:16:46
A:
Check out the JQuery UI 'highlight' effect at http://jqueryui.com/demos/effect/
$( function() {
$("textBoxId")
.click( function(){
var options = {};
$("#textBoxId").effect("Highlight",options,500,callback);
});
});
Cubic Compass
2009-07-24 04:32:35