Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM TableData rowSpan Property

  • Difficulty Level : Basic
  • Last Updated : 19 May, 2021
Geek Week

The DOM TableData rowSpan Property in HTML DOM is used to set or return the value of the rowspan attribute. The rowspan attribute in HTML specifies the number of rows a cell should span.

Syntax: 

  • It returns the rowSpan property. 
tabledataObject.rowSpan
  • It is used to set the rowSpan property. 
tabledataObject.rowSpan = number

Property Values: It contains the value i.e number which specifies the number of rows a cell should span.
Return Values: It returns a numeric value which represents the number of rows a cell should span.

Example-1: This Example returns a rowspan Property. 

html




<!DOCTYPE html>
<html>
 
<head>
    <style>
        table,
        th,
        td {
            border: 1px solid green;
        }
    </style>
</head>
 
<body>
 
    <h1 style="color:green;">
            GeeksForGeeks
        </h1>
 
    <h2>
          DOM TableData rowSpan Property
      </h2>
 
    <table>
        <tr>
            <td id="myTd"
                rowspan="3">
                Geeks
            </td>
            <td>For</td>
            <td>Geeks</td>
        </tr>
    </table>
    <br>
    <button onclick="myFunction()">
        Click Here!
    </button>
 
    <p id="demo" style="font-size:24px;
                  colorgreen;">
    </p>
 
 
    <script>
        function myFunction() {
            // Accessing Table data
            var x =
                document.getElementById(
                    "myTd").rowSpan;
           
            document.getElementById(
              "demo").innerHTML = x;
        }
    </script>
</body>
 
</html>

Output: 
Before Clicking On Button: 
 



After Clicking On Button: 
 

Example-2: This Example sets the rowspan Property. 

html




<!DOCTYPE html>
<html>
 
<head>
    <style>
        table,
        th,
        td {
            border: 1px solid green;
        }
    </style>
</head>
 
<body>
 
    <body>
 
        <h1 style="color:green;">
            GeeksForGeeks
        </h1>
 
        <h2>
          DOM TableData rowSpan Property
      </h2>
 
        <table>
            <tr>
                <td id="myTd"
                    rowspan="3">
                  Geeks
              </td>
                <td>For</td>
                <td>Geeks</td>
            </tr>
        </table>
        <br>
        <button onclick="myFunction()">
            Click Here!
        </button>
 
        <p id="demo"
           style="font-size:24px;
                  colorgreen;">
      </p>
 
 
        <script>
            function myFunction() {
                // Accessing Table data
                var x =
                    document.getElementById(
                    "myTd").rowSpan = "2";
               
                document.getElementById("demo").innerHTML =
                  "The value of the rowspan "+
                   "attribute was changed to "
                + x;
            }
        </script>
    </body>
 
</html>

Output: 
Before Clicking On Button: 
 

After CLicking On Button: 
 

Supported Browsers: 

  • Google Chrome 
  • Mozilla Firefox 
  • Edge 
  • Safari 
  • Opera

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :