Javascript DOM HTML TableHeader colSpan Property set

Introduction

Change the number of columns a cell should span:

document.getElementById("myTh").colSpan = "1";

Click the button to change the value of the colspan attribute, from 2 to 1, of th with id "myTh".

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>//from   www. j ava 2s. c o  m
</head>
<body>
<table>
  <tr>
    <th id="myTh" colspan="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").colSpan = "1";
}
</script>

</body>
</html>

The colSpan property sets or gets the value of the colspan attribute.

The colspan attribute specifies the number of columns a table cell should span.

The colSpan property accepts and returns a number type value.




PreviousNext

Related