Javascript DOM HTML TableData headers Property get

Introduction

Return the value of the headers attribute of a <td> element with id=myTd:

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

Click the button to return the value of the headers attribute of td with id=myTd.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table {/*ww  w. j  a v a 2 s. com*/
  width: 100%;
}

table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>
<table>
  <tr>
    <th id="name">Name</th>
    <th id="email">Email</th>
    <th id="phone">Phone</th>
    <th id="addr">Address</th>
  </tr>
  <tr>
    <td id="myTd" headers="name">java2s.com</td>
    <td headers="email">someone@example.com</td>
    <td headers="phone">+123456789</td>
    <td headers="addr">PO 1234, Main Street U.S.A.</td>
  </tr>
</table>
<br>

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

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

<script>
function myFunction() {
  var x = document.getElementById("myTd").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.

Property Values

Value Description
ids sets 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