tags:

views:

108

answers:

4

How can I highlight all the text within a textbox when it is clicked using jQuery?

+1  A: 

Using jQuery to Highlight (Select) All Text in a Textbox

http://www.willstrohl.com/Blog/tabid/66/EntryId/321/Using-jQuery-to-Highlight-Select-All-Text-in-a-Textbox.aspx

Robert Harvey
I couldn't get that to work.
Ben Shelock
+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
+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
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