Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

How to get the value of a textarea in jQuery ?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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.


My Personal Notes arrow_drop_up
Last Updated : 03 Aug, 2021
Like Article
Save Article
Similar Reads
Related Tutorials