Javascript examples for DOM HTML Element:Column
The span property sets or gets the span attribute of a <col>.
Set the formMethod property with the following Values
Value | Description |
---|---|
number | Sets the number of columns a <col> element should span. Negative values are not allowed |
A Number, representing the number of columns
The following code shows how to Set the background color of the first two columns to red:
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 1px solid black; } </style>//from w w w . j a v a 2s . c o m </head> <body> <table> <colgroup> <col id="myCol"> <col style="background-color:yellow"> </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> <p id="demo"></p> <button onclick="myFunction()">set the background color of the first two columns to red</button> <script> function myFunction() { document.getElementById("myCol").span = "2"; document.getElementById("myCol").style.backgroundColor = "red"; } </script> </body> </html>