You are here: Reference > JavaScript > client-side > HTML DOM > methods > createTHead (table)

createTHead method (table)

Browser support:
Creates an empty thead element and adds it to the current table.
If a thead already exists on the current table, the createTHead method returns it and does not create a new one.
Another way to create a thead element is to use the createElement method. To remove the header from a table, use the deleteTHead method.


object.createTHead ( );
You can find the related objects in the Supported by objects section below.

Return value:

Returns the newly created or the existing thead element.

Example HTML code 1:

This example illustrates the use of the createTHead method:
    <script type="text/javascript">
        function CreateHeader () {
            var table = document.getElementById ("myTable");
            if (!table.tHead) {
                var header = table.createTHead ();
                var row = header.insertRow (0);
                var cell = row.insertCell (0);
                cell.innerHTML = "<b>Header for the table.</b>";
    <table id="myTable" border="1px">
                <td>This text is inside the table.</td>
    <br /><br />
    <button onclick="CreateHeader ();">Create a header for the table!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content