Javascript examples for DOM HTML Element:ColumnGroup
The span property sets or gets the span attribute of a <colgroup>.
Set the formMethod property with the following Values
Value | Description |
---|---|
number | Sets the number of columns a <colgroup> element should span |
A Number, representing the number of columns
Set the background color of the first two columns to red:
<!DOCTYPE html> <html> <head> <style> table, th, td { border:1px solid black; } </style>//ww w . ja v a 2 s . c om </head> <body> <table> <colgroup id="myColgroup"></colgroup> <tr> <th>ISBN</th> <th>Title</th> <th>Price</th> </tr> <tr> <td>001</td> <td>HTML</td> <td>$5</td> </tr> <tr> <td>002</td> <td>CSS</td> <td>$5</td> </tr> </table> <button onclick="myFunction()">set the background color of the first two columns</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("myColgroup").span = "2"; document.getElementById("myColgroup").style.backgroundColor = "blue"; } </script> </body> </html>