Get Column Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Column

Introduction

The Column object represents an HTML <col> element.

You can access a <col> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 1px solid black;
}
</style>/*w  w w.j  a va2 s  . co m*/
</head>
<body>

<table>
  <colgroup>
    <col id="myCol" span="2" style="background-color:#EEE">
    <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>$3</td>
  </tr>
  <tr>
    <td>002</td>
    <td>CSS</td>
    <td>$9</td>
  </tr>
</table>

<button onclick="myFunction()">get the number of columns a COL element should span</button>

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

<script>
function myFunction() {
    var x = document.getElementById("myCol").span;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials