Javascript examples for DOM HTML Element:TableHeader
The colSpan property sets or gets the colspan attribute, which sets the number of columns a table cell should span.
Set the colSpan property with the following Values
Value | Description |
---|---|
number | Sets the number of columns a cell should span |
A Number, representing the number of columns a table cell should span
The following code shows how to change the number of columns a cell should span:
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; } </style>/*www . j ava2 s . com*/ </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>