Column span Property - Javascript DOM HTML Element

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

Return Value

A Number, representing the number of columns

The following code shows how to Set the background color of the first two columns to red:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
table, th, td {
    border: 1px solid black;
</style>//from  w w  w . j a  v a  2s  .  c  o  m

    <col id="myCol">
    <col style="background-color:yellow">

<p id="demo"></p>

<button onclick="myFunction()">set the background color of the first two columns to red</button>

function myFunction() {
    document.getElementById("myCol").span = "2";
    document.getElementById("myCol").style.backgroundColor = "red";


Related Tutorials