HTML | DOM Textarea rows Property

The DOM Textarea rows Property is used to set or return the value of a rows attribute of a textarea field. The rows attribute specify the number of visible text lines for the control i.e the number of rows to display.

Syntax:

  • It is used to Return the rows property:
    textareaObject.rows
  • It is used to Set the rows property:
    textareaObject.rows = number

Property Values:



  • number: It specifies a visible number of rows in a textarea field.

Return Value: It returns a numeric value which represent the height of a textarea field contains the characters.

Example-1: HTML program to illustrate set the DOM Textarea rows Property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Textarea rows Property</title>
    <style>
        h1,
        h2 {
            text-align: center;
        }
    </style>
</head>
  
<body style="text-align:center;">
    <h1 style="color: green;"
            GeeksforGeeks 
        </h1>
  
    <h2
            DOM Textarea rows Property 
        </h2>
  
    <!-- Below id assigned to Textarea Element -->
    <textarea id="GFG" rows="5" cols="23">
        This paragraph has number of rows equal to 5.
    </textarea>
    <br>
    
    <button type="button" 
            onclick="myGeeks()">
      Submit
    </button>
  
    <script>
        function myGeeks() {
            
         // Access textarea element.
          document.getElementById("GFG").rows = 
              "10";
        }
    </script>
</body>
  
</html>

chevron_right


Output :

Before Clicking On Button:

After Clicking On Button :

Example-2: HTML program to illustrate to return the DOM Textarea rows Property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Textarea rows Property</title>
    <style>
        h1,
        h2 {
            text-align: center;
        }
    </style>
</head>
  
<body style="text-align:center;">
    <h1 style="color: green;"
            GeeksforGeeks 
        </h1>
  
    <h2
            DOM Textarea rows Property 
        </h2>
  
    <!-- Below id assigned to Textarea Element -->
    <textarea id="GFG" rows="5" cols="23">
        This paragraph has number of rows equal to 5.
    </textarea>
    <br>
    <button type="button" onclick="myGeeks()">Submit</button>
    <p id="sudo"></p>
    <script>
        function myGeeks() {
            
            // Return number of rows in the textare.
            var x = document.getElementById("GFG").rows;
            document.getElementById("sudo").innerHTML = 
              "There are" + x + " rows in a Textarea height.";
        }
    </script>
</body>
  
</html>

chevron_right


Output:

Before Clicking On Button:

After Clicking On Button:

Supported Browsers: The browser supported by Textarea rows Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


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.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.