TableHeader rowSpan Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:TableHeader

Description

The rowSpan property sets or gets the rowspan attribute, which sets the number of rows a table cell should span.

Set the rowSpan property with the following Values

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

Return Value

A Number, representing the number of rows a table cell should span

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 1px solid black;
}
</style>/* ww w  .j  a  v a 2s .c o m*/
</head>
<body>

<table>
  <tr>
    <th id="myTh" rowspan="2">Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$100</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$100</td>
  </tr>
</table>
<br>

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

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

</body>
</html>

Related Tutorials