TableHeader headers Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:TableHeader


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>
table, th {
    border: 1px solid black;
</style>//w  w  w .  ja  v a  2s  .c o m

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

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

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

function myFunction() {
    var v = document.getElementById("myTh").headers;
    document.getElementById("demo").innerHTML = v;


Related Tutorials