luckidtk
luckidtk

Reputation: 45

The problem of formatting text pick up textarea with javascript

I can't put the code below into "textarea" because of a line break (enter):

1) install

2) Ok

3) Like

It works if I write this without breaking the line:

1) install 2) Ok 3) Like

Is there any way to put the code into textarea without interfering with the code? The above code is fixed from the database (BBcode).

html

<textarea class="message" rows="10" cols="60"></textarea>

javascript

$('.message').html('1) install
2) Ok
3) Like'); 

Demo: https://jsfiddle.net/v9kpdn4t/

Upvotes: 0

Views: 68

Answers (1)

charlietfl
charlietfl

Reputation: 171679

Use val() not html() for <textarea>

const str=`1) install

2) Ok

3) Like

html`

$('.message').val(str)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea class="message" rows="10" cols="60"></textarea>

Upvotes: 1

Related Questions