W3Schools.com

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 type="text/javascript">
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
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE