HTML DOM Textarea rows Property


The HTML DOM Textarea rows returns and modify the value of rows attribute of a text area element in an HTML document.

Syntax

Following is the syntax −

1. Returning rows

object.rows

2. Adding rows

object.rows = “number”

Let us see an example of HTML DOM Textarea rows Property:

Example

Live Demo

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      background: lightseagreen;
      height: 100vh;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
   }
</style>
<body>
<h1>DOM Textarea rows Property Demo</h1>
<textarea>Hi! I'm a textarea element in an HTML document with some dummy text.</textarea>
<button onclick="set()" class="btn">Set Rows = 8</button>
<script>
   function set() {
      document.querySelector("textarea").rows = '8';
   }
</script>
</body>
</html>

Output

Click on “Set rows = 8” button to set the value of rows attribute to 50.

Updated on: 16-Feb-2021

64 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements