Return the number of columns a <col> element should span:
var x = document.getElementById("myCol").span;
Click the button to return the value of the span attribute of the column.
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; } </style>/*from ww w .j av a2 s . com*/ </head> <body> <table> <colgroup> <col id="myCol" span="2" style="background-color:red"> <col style="background-color:yellow"> </colgroup> <tr><th>ISBN</th> <th>Title</th> <th>Price</th></tr> <tr><td>101</td> <td>HTML</td> <td>$5</td></tr> <tr><td>102</td> <td>CSS</td> <td>$4</td></tr> </table> <p id="demo"></p> <button onclick="myFunction()">Test</button> <script> function myFunction() { var x = document.getElementById("myCol").span; document.getElementById("demo").innerHTML = x; } </script> </body> </html>