How to get textarea text using jQuery?

Learn how to access or get the text present in the textarea using jQuery?
Submitted by Pratishtha Saxena, on February 10, 2023

Getting textarea's text

The textarea is an HTML element that is usually used whenever multiple line input has to be given, say, in case of providing address, comments, etc. Now, over here we will be learning how to access and get that input given by the user in the textarea. For this task, the very widely used val() method of jQuery will be considered.

jQuery val() Method

The val() method helps to get the value of the selected form field or the element. The specified element is selected using the selector and further using this method its value can be accessed. If there is no 'value' attribute for that element, then val() returns its text value of its.



This is a very simple method and does not take any parameters for returning the value of the selected element in jQuery. In the example given below, a comment box can be seen. When the comment is entered there and hence submitted, that comment will be visible in the following comment section.

jQuery example to get textarea text

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src=""></script>
      margin: 2%;
    <h2>jQuery Get Textarea Text</h2>
    <h4>Submit the comment to view the output.</h4>
      <p>Welcome to Include Help !</p>
      <p>This is a JavaScript Tutorial.</p>
      <p>Thanks for Visiting !</p>
      Enter Comment: 
    <h4 id="one"><u>Comment Section</u></h4>
  <script type="text/javascript">
            $('h4#one').append('<br><br>' + $('textarea').val());


Example: How to get textarea text using jQuery?

All jQuery Examples

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.