Javascript Reference - HTML DOM ColumnGroup Object








The ColumnGroup class represents an HTML <colgroup> element.

ColumnGroup Object Properties

Property Description
span Sets or gets the span attribute for a column group

Standard Properties and Events

The ColumnGroup object supports the standard properties and events.

Example

The following code shows how to get <colgroup> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<table>
  <colgroup id="myColgroup" span="2" style="background:red"></colgroup>
  <tr>
    <th>ID</th>
    <th>Title</th>
    <th>Price</th>
  </tr><!--   w  ww.ja  v  a  2  s  .c  o m-->
  <tr>
    <td>3</td>
    <td>HTML</td>
    <td>$3</td>
  </tr>
  <tr>
    <td>5</td>
    <td>CSS</td>
    <td>$9</td>
  </tr>
</table>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myColgroup").span;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: