Javascript DOM HTML ColumnGroup span Property get

Introduction

Return the number of columns a <colgroup> element should span:

var x = document.getElementById("myColgroup").span;

Click the button to return the value of the span attribute of the colgroup element.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>/*from ww w .  j  av a2 s  .c om*/
</head>
<body>

<table>
  <colgroup id="myColgroup" span="2" style="background:red"></colgroup>
  <tr><th>ISBN</th>   <th>Title</th>    <th>Price</th></tr>
  <tr><td>101</td>    <td>HTML</td>     <td>$5</td></tr>
  <tr><td>102</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("myColgroup").span;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related