user2580777
user2580777

Reputation: 79

highlight and select a text of a input with jQuery

I cannot find a solution in stackoverflow. I have an input filed and a value. I want the value to be selected and highlighted, so the user can easily copy the text. How can I do it with jQuery?

<input value="copy this text easily"  />

Upvotes: 0

Views: 119

Answers (2)

Sushanth --
Sushanth --

Reputation: 55750

Try

$('input').focus()

Check Fiddle

You may need to change the selector though. I wrote a generic selector since there in only 1 input in the example.

Upvotes: 1

Shawn31313
Shawn31313

Reputation: 6052

With jQuery you can use the select function:

$("input").select();

Upvotes: 1

Related Questions