Return the number of columns a specific table cell should span:
var x = document.getElementById("myTd").colSpan;
Click the button to return the value of the colspan attribute of td with id=myTd
.
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; } </style>//from w ww .ja va 2 s .c om </head> <body> <table> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td id="myTd" colspan="2">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("myTd").colSpan; document.getElementById("demo").innerHTML = "The value of colspan is: " + x; } </script> </body> </html>