Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Textarea rows Property

  • Last Updated : 11 Feb, 2019

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.






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

Output :

Before Clicking On Button:

After Clicking On Button :

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




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

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

Attention reader! Don’t stop learning now. Get hold of all the important Comcompetitivepetitve Programming concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :