Table createTHead() Method
Example
Create a <thead> element (and insert a <tr> and <td> element to it):
// Find a <table> element with id="myTable":
var table = document.getElementById("myTable");
// Create an empty <thead> element and add it to the table:
var header =
table.createTHead();
// Create an empty <tr> element and add it to
the first position of <thead>:
var row =
header.insertRow(0);
// Insert a new cell
(<td>) at the first position of the "new" <tr> element:
var cell = row.insertCell(0);
// Add some bold text in the new cell:
cell.innerHTML = "<b>This is a
table header</b>";
Try it yourself »
Definition and Usage
The createTHead() method creates an empty <thead> element and adds it to the table.
Note: If a <thead> element already exists on the table, the createTHead() method returns the existing one, and does not create a new one.
Note: The <thead> element must have one or more <tr> tags inside.
Tip: To remove the <thead> element from a table, use the deleteTHead() method.
Browser Support
The createTHead() method is supported in all major browsers.
Syntax
tableObject.createTHead()
Parameters
None |
Technical Details
Return Value: | The newly created (or an existing) <thead> element |
---|
More Examples
Example
Create and delete a <thead> element:
function myCreateFunction() {
var table =
document.getElementById("myTable");
var header =
table.createTHead();
var row = header.insertRow(0);
var cell = row.insertCell(0);
cell.innerHTML =
"<b>This is a table header</b>";
}
function myDeleteFunction() {
document.getElementById("myTable").deleteTHead();
}
Try it yourself »
Related Pages
HTML reference: HTML <thead> tag
Table Object