TableHeader headers attribute

Definition and Usage

headers Sets or returns the value of the headers attribute.

<th> headers attribute Specifies a list of header cells that contain the title information for the current data cell.

See also:

HTML Reference Manual:HTML <th> Tag

Example

Example 1

Return the headers attribute value of the <th> element with id "myTh":

var x = document.getElementById("myTh").headers;

Try it yourself

Example 2

Display the cell titles of the second row:

var table = document.getElementById("myTable");
var txt = "";
var i;
for (i = 0; i < table.rows[1].cells.length; i++) {
  txt = txt + table.rows[1].cells[i].headers + "<br>";
}

Try it yourself

Example 3

Change the headers attribute of the <th> element with id "myTh":

document.getElementById("myTh").headers = "newValue";

Try it yourself

Syntax

Return the headers attribute:

tableheaderObject.headers

Set the headers attribute:

tableheaderObject.headers = header_ids

Attribute Value

Value Description
header_ids Specifies a list of one or more header cell ids related to the table cell, separated by spaces.

Technical Details

Return Value: A string value that contains a list of header cell identifiers separated by spaces.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Related Pages

HTML Reference Manual:HTML <th> headers Attribute