TableHeader headers Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:TableHeader

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 <th> element with id "myTh":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th {
    border: 1px solid black;
}
</style>//w  w  w .  ja  v a  2s  .c o m
</head>
<body>

<table id="myTable">
  <tr>
    <th id="name" colspan="3">Name</th>
  </tr>
  <tr>
    <th id="myTh" headers="fname">First name</th>
    <th headers="mname">Middle name</th>
    <th headers="lname">Last name</th>
  </tr>
</table>
<br>

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

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

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

</body>
</html>

Related Tutorials