Open In App

How to get the value of a textarea in jQuery ?

Last Updated : 03 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

We can get the value of textarea in jQuery with the help of val() method . The val() method is used to get the values from the elements such as textarea, input and select. This method simply returns or sets the value attribute of the selected elements and is mostly used with the form elements.   When called on empty collection or when the input is not given, it returns undefined or blank output.

HTML




<!DOCTYPE html>
<html>
    <head>
        <title>How to get the value of textArea</title>
        <script src=
        </script>
    </head>
    <body>
        <center>
            <h1 style="color: green;">GeeksforGeeks</h1>
            <textarea id="txtArea"></textarea><br><br>
            <button id="btn">Show Text</button>
        </center>
    </body>
  
    <script>
        $(document).ready(function () {
            
            //This function called when the button is clicked
            $("#btn").click(function () {
                
                // val() method is used to get the values from 
               // textarea and stored in txt variable
                var txt = $("#txtArea").val();
                alert(txt);
            });
        });
    </script>
</html>


Output:

jQuery is an open source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous with it’s philosophy of “Write less, do more”.
You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads