0

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"  />
user2580777
  • 69
  • 1
  • 6
  • What exactly do you want to do? Create an `` element and give it a `value`? – Seth Jul 19 '13 at 00:25
  • possible dupe of http://stackoverflow.com/questions/480735/select-all-contents-of-textbox-when-it-receives-focus-javascript-or-jquery – kapa Jun 04 '14 at 11:41

2 Answers2

1

With jQuery you can use the select function:

$("input").select();
Shawn31313
  • 5,870
  • 3
  • 32
  • 78
1

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.

Sushanth --
  • 54,565
  • 8
  • 62
  • 98