ColumnGroup span Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:ColumnGroup

Description

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

Return Value

A Number, representing the number of columns

Set the background color of the first two columns to red:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials