Javascript DOM HTML ColumnGroup span Property set

Introduction

Set the background color of the first two columns to red:

Click the button to set the background color of the first two columns.

View in separate window

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

<table>
  <colgroup id="myColgroup"></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() {
  document.getElementById("myColgroup").span = "2";
  document.getElementById("myColgroup").style.backgroundColor = "red";
}
</script>

</body>
</html>

The span property sets or gets the span attribute of a column group.

The span attribute sets the number of columns a <colgroup> element should span.

The span property accepts and returns a number value.




PreviousNext

Related