King Kong
King Kong

Reputation: 2915

Select all text in textarea jquery

How to make all text in textarea selected when user open it through jquery?

Upvotes: 3

Views: 5613

Answers (3)

thecodeparadox
thecodeparadox

Reputation: 87073

$('textarea').focus(function() {
  this.select();
})

DEMO

From the line "when user open it through jquery" I think you need something like:

$('textarea').slideDown(function() {
    $(this).focus();
}).focus(function() {
    this.select();
});

Here I assume your textarea is hidden and you opened it using jQuery event and after open it text will be selected by default.

DEMO

Upvotes: 0

epascarello
epascarello

Reputation: 207557

Input.select

var eraInput = document.getElementById('era');
eraInput.select();

Upvotes: 1

Alex
Alex

Reputation: 35407

$('textarea').on('mouseup', function() { $(this)[0].select(); });​

http://jsfiddle.net/Tu9N7/

Upvotes: 6

Related Questions