Javascript Reference - HTML DOM TableData rowSpan Property








The rowSpan property sets or gets the rowspan attribute.

The rowspan attribute specifies the number of rows a table cell should span.

Browser Support

rowSpan Yes Yes Yes Yes Yes

Syntax

Return the rowSpan property.

var v = tabledataObject.rowSpan

Set the rowSpan property.

tabledataObject.rowSpan=number

Property Values

Value Description
number Set the number of rows a cell should span




Return Value

A Number type value representing the number of rows a table cell should span.

Example

The following code shows how to get the number of rows a cell should span.


<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {<!--  ww  w .j ava  2 s  .c  o  m-->
    border: 1px solid black;
}
</style>
</head>
<body>
<table border="1">
  <tr>
    <th>Item</th>
    <th>Price</th>
  </tr>
  <tr>
    <td id="myTd" rowspan="2">A</td>
    <td>$1</td>
  </tr>
  <tr>
    <td>B</td>
    <td>$0</td>
  </tr>
</table>
<br> 

<button onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myTd").rowSpan;
    document.getElementById("demo").innerHTML = "The value of rowspan is: " + x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the number of rows a table cell should span.


<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {<!--  w  w w  . j a  v  a 2  s.  co  m-->
    border: 1px solid black;
}
</style>
</head>
<body>
<table border="1">
  <tr>
    <th>Item</th>
    <th>Price</th>
  </tr>
  <tr>
    <td id="myTd" rowspan="2">A</td>
    <td>$1</td>
  </tr>
  <tr>
    <td>B</td>
    <td>$1</td>
  </tr>
</table>
<br> 

<button onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("myTd").rowSpan = "1";
}
</script>

</body>
</html>

The code above is rendered as follows: