Javascript DOM HTML TableHeader rowSpan Property get

Introduction

Return the number of rows a specific table cell should span:

var x = document.getElementById("myTh").rowSpan;

Click the button to return the value of the rowspan attribute of th with id "myTh".

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>/*from  w ww .j  a  va  2 s  .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>

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

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

</body>
</html>



PreviousNext

Related