The Column
object represents an HTML <col>
element.
Property | Description |
---|---|
span | Sets or gets the value of the span attribute |
The Column object supports the standard properties and events.
The following code shows how to get a <col> element by using getElementById().
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {<!-- w ww .j a v a 2 s. c o m-->
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<colgroup>
<col id="myCol" span="2" style="background-color:red">
<col style="background-color:yellow">
</colgroup>
<tr><th>A</th><th>B</th><th>Price</th></tr>
<tr><td>3</td><td>HTML</td><td>$3</td></tr>
<tr><td>5</td><td>CSS</td><td>$4</td></tr>
</table>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myCol").span;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: