JavaScript table object method: createTHead()
[this page | pdf | back links]
The createTHead() method of the JavaScript
DOM object
corresponding to the HTML <table> element
creates an empty <thead>
element and adds it to the table. If a <thead> element
already exists in the table then it returns the existing one, without creating
a new one.
It has the following
syntax with no parameters:
object.createTHead()
EXAMPLE: [This feature does not appear to be supported by your browser]
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,td,tr,caption {border: thin solid black; border-collapse: collapse;}
thead {background-color: yellow;}
tfoot {background-color: Aquamarine;}
</style>
</head>
<body>
<span id="element"></span>
<script>
var x = document.createElement("TABLE");
x.createCaption().innerHTML="A table";
var y = x.createTHead();
var y0 = y.insertRow(0);
var y00 = y0.insertCell(0);
y00.innerHTML = "column 1";
var z = x.createTFoot()
var z0 = z.insertRow(0);
var z00 = z0.insertCell(0);
z00.innerHTML = "contents of column 1";
document.getElementById("element").appendChild(x);
</script>
</body>
</html>
|
FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodTableCreateTHead() {
var z = document.createElement("TABLE"); return !!z.tHead;
} |
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)