Javascript DOM HTML TableHeader headers Property get

Introduction

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

var x = document.getElementById("myTh").headers;

Click the button to return 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>/*ww  w .  j  a  va2s. c om*/
</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() {
  var x = document.getElementById("myTh").headers;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The headers property sets or gets the value of the headers attribute.

The headers attribute sets a list of header cells containing header information for the current data cell.

Value Description
idsset a space-separated list of id's to one or more header cells

The headers property returns a String containing a space-separated list of header cell identifiers.




PreviousNext

Related