How to get the value of a textarea in jQuery ?

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.