textarea value update without delete the previous Javascript

Viewed 188

what I'm trying to do to insert new data in text area without effect the previous one:

<textarea class="form-control" rows="5" id="data" name="data">
roma is the most visit
</textarea>

  $("#data").val('new line without delete the previous one ');

what I expect:

<textarea class="form-control" rows="5" id="data" name="data">
roma is the most visit
new line without delete the previous one 
</textarea>

So how can I do it?

1 Answers

Use .append() instead of .val() (doc):

$("#data").append('new line without delete the previous one ');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea class="form-control" rows="5" id="data" name="data">
roma is the most visit
</textarea>

Related