jQuery

jQuery Textarea Value Examples (Using Get, Set, Append)

Ever wondered how to Get Textarea value, Set Textarea value & Append to Textarea value using jQuery? In this article, I am going to show you easy ways of doing all the above. Actual code is just 1 line, so it’s super easy to follow and implement.

Examples to Get, Set, Append To Textarea value

Let’s say you have a textarea with ID “comments”.

Example 1: Get Textarea value using jQuery:

This code simply gets the existing value of the textarea.

$("#comments").val();

Example 2: Set Textarea value using jQuery:

This code sets the value of the textarea to “This is my custom text.”. Note that it WILL OVERWRITE any of the existing textarea value.

$("#comments").val('This is my custom text.');

Example 3: Append to Textarea value using jQuery:

If you do not want the existing textarea value to be overwritten and would instead want a new value to be appended to the existing value, then use the following code:

$('#comments').val( $('#comments').val() + 'This new text will be appended to existing value in textarea.' );
Simple, isn’t it?

Do you know of any other ways to Get, Set and Append to Textarea value using jQuery? Feel free to share by commenting below.

Share your thoughts, comment below now!

*

*