td/th headersProperty
td/th Object
Definition and Usage
The headers property sets or returns the list of header cells that contain header information for the current data cell.
The value of this property is a quoted list of names; these names are the names of different header cells defined by the id attribute.
Syntax
Set the headers property:
tdObject.headers="header_ids"
or
thObject.headers="header_ids"
or
thObject.headers="header_ids"
Return the headers property:
tdObject.headers
or
thObject.headers
or
thObject.headers
Tip:The headers property has no default value.
| Value | Description |
|---|---|
| header_ids | Defines the list of header cell ids separated by spaces. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the headers property.
Example
Example
Display the header of the second row:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<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</th>
<th id="email">Email</th>
<th id="phone">Phone</th>
<th id="addr">Address</th>
</tr>
<tr>
<td headers="name">John Doe</td>
<td headers="email">[email protected]</td>
<td headers="phone">+45342323</td>
<td headers="addr">Rosevn 56,4300 Sandnes,Norway</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Get the cell header of the second row</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<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</th>
<th id="email">Email</th>
<th id="phone">Phone</th>
<th id="addr">Address</th>
</tr>
<tr>
<td headers="name">John Doe</td>
<td headers="email">[email protected]</td>
<td headers="phone">+45342323</td>
<td headers="addr">Rosevn 56,4300 Sandnes,Norway</td>
</tr>
</table>
<br>
<button type="button" onclick="displayResult()">Get the cell header of the second row</button>
</body>
</html>
Try it yourself »
td/th Object Other Extensions