PHG
PHG

Reputation: 180

Add text to textarea using class name

When the user clicks a tag, I want to add append text to textarea using class name.

Click event handler works,but not adding text to the textarea.

Here's the code I have so far.

var boardName;

$(document).ready(function() {
    $('.js-open-card-composer').click(function() {
         boardName = document.title.replace(' | Trello', '');
         $('.list-card-composer-textarea').text += boardName;

    });
});

And, Here's the text area

<textarea class="list-card-composer-textarea js-card-title" style="overflow: hidden; word-wrap: break-word; height: 36px;"></textarea>

Thanks!

Upvotes: 0

Views: 1983

Answers (2)

Keerthi
Keerthi

Reputation: 923

Use html instead of text

var boardName;

    $('.js-open-card-composer').click(function() {
         boardName = 'test';
         var data = $('.list-card-composer-textarea').html();
         $('.list-card-composer-textarea').html(data+boardName);

    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea class="list-card-composer-textarea js-card-title" style="overflow: hidden; word-wrap: break-word; height: 36px;"></textarea>

<div class="js-open-card-composer" style="width:20px;height:20px;border:1px solid red"></div>

Upvotes: 0

jrath
jrath

Reputation: 990

jQuery text() is function so instead of

$('.list-card-composer-textarea').text += boardName;

use

var data = $('.list-card-composer-textarea').text();
$('.list-card-composer-textarea').text( data + boardName);

Upvotes: 1

Related Questions