How to make text to jump new line in the textarea?

I have a problem making a text jump to a new line in the textarea. It will show </br> words in the textarea. May I know how to avoid </br> words show in the text area and can make the text jump to a new line? Hope someone can guide me on how to solve this problem. Thanks.

Below is my sample coding:

$("textarea[name='default_kandungan']").val('Alex</br>Peter</br>John')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 <textarea type="text" " id="default_kandungan" name="default_kandungan" value="" title="Default Kandungan"></textarea>

Actually, I want the expected results like below the picture:

output 1

Upvotes: 0

Views: 486

Answers (1)

Not A Robot
Not A Robot

Reputation: 2694

Instead of using <br> tag directly, use \n

$("textarea[name='default_kandungan']").val('Alex\nPeter\nJohn')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 <textarea type="text"  id="default_kandungan" name="default_kandungan" value="" title="Default Kandungan"></textarea>

Upvotes: 2

Related Questions