Search w3schools.com:

SHARE THIS PAGE

td/th headers Property

td/th Object Reference td/th Object

Definition and Usage

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

This property sets or returns a space-separated list of header cell ids.

Syntax

Set the headers property:

tdObject.headers="header_ids"

or

thObject.headers="header_ids"

Return the headers property:

tdObject.headers

or

thObject.headers

Tip: There is no default value for the headers property.

Value Description
header_ids Defines a space-separated list of header cell ids


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The headers property is supported in all major browsers.


Example

Example

Display cell headers of second row:

<html>
<head>
<script>
function displayResult()
{
var table=document.getElementById("myTable");
for (var i=0;i<table.rows[1].cells.length;i++)
  {
  alert(table.rows[1].cells[i].headers);
  }
}
</script>
</head>
<body>

<table id="myTable" border="1" width="100%">
  <tr>
    <th id="name">Name</td>
    <th id="email">Email</td>
    <th id="phone">Phone</td>
    <th id="addr">Address</td>
  </tr>
  <tr>
    <td headers="name">John Doe</td>
    <td headers="email">someone@example.com</td>
    <td headers="phone">+45342323</td>
    <td headers="addr">Rosevn 56,4300 Sandnes,Norway</td>
  </tr>
</table>
<br>

<button type="button" onclick="displayResult()">Get cell headers of second row</button>

</body>
</html>

Try it yourself »


td/th Object Reference td/th Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]