Joe Morano
Joe Morano

Reputation: 1895

How to activate a textarea with jQuery?

I have a textarea (#textarea), which I want to "activate" when a button (#activate) is clicked. By "activate", I mean the blinking prompt should appear and you should be able to type into the textarea. In other words, clicking on #activate should have the same effect as clicking on the actual textarea.

<div id="activate">ACTIVATE</div>

<%= form_for @comment do |f| %>
  <%= f.text_area :text, id:"textarea" %>
  <%= f.submit "Go" %>
<% end %>

Is this possible using jQuery?

Upvotes: 0

Views: 615

Answers (2)

Faust
Faust

Reputation: 15404

The relevant event is called focus. With jQuery you can set focus like this:

$('#textarea').focus();

Upvotes: 1

AmmarCSE
AmmarCSE

Reputation: 30607

You can use jQuery focus()

$('#activate').click(function() {
  $('#textarea').focus();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<div id="activate">ACTIVATE</div>

<textarea id="textarea"></textarea>

Upvotes: 2

Related Questions