TableData headers Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:TableData

Description

The headers property sets or gets the headers attribute, which sets a list of header cells containing header information for the current data cell.

Set the headers property with the following Values

Value Description
header_ids Sets a space-separated list of id's to one or more header cells the table cell is related to

Return Value

A String, containing a space-separated list of header cell identifiers

The following code shows how to return the value of the headers attribute of a <td> element with id "myTd":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table {/*from  w  ww  .ja  v a2 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">your name</td>
   <td headers="email">someone@example.com</td>
   <td headers="phone">+123456789</td>
   <td headers="addr">Main Street</td>
 </tr>
</table>
<br>

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

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

<script>
function myFunction() {
    var v = document.getElementById("myTd").headers;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials