Skip to content
Related Articles

Related Articles

How to get the value of a textarea in jQuery ?
  • Last Updated : 29 May, 2020

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:




My Personal Notes arrow_drop_up
Recommended Articles
Page :