Javascript DOM HTML TableHeader headers Property set

Introduction

Change the value of the headers attribute of a <th> element with id "myTh":

document.getElementById("myTh").headers = "newValue";

Click the button to change the value of the headers attribute of th with id "myTh".

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th {
  border: 1px solid black;
}
</style>//from  w ww .  j a va  2 s .c o  m
</head>
<body>
<table id="myTable">
  <tr>
    <th id="name" colspan="3">Name</th>
  </tr>
  <tr>
    <th id="myTh" headers="fname">First name</th>
    <th headers="mname">Middle name</th>
    <th headers="lname">Last name</th>
  </tr>
</table>
<br>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  document.getElementById("myTh").headers = "newValue";
  document.getElementById("demo").innerHTML = "The value of the headers attribute was changed.";
}
</script>

</body>
</html>



PreviousNext

Related