How to create Header of a table in JavaScript

In this article I have described about table createTHead() method used in JavaScript.
  • 6105

Table createTHead() method in JavaScript

  • As we know that a table object represents a table in HTML.
  • If want to create the Header and delete that Header from table then we can use table createTHead() method.

Browser support

Following are the main browsers which support the table createTHead() method

  • Internet Explorer.
  • Firefox.
  • Opera.
  • Google Chrome.
  • Safari.


The syntax of table createTHead() method as follows


Lets take an example

<!DOCTYPE html>



<script type="text/javascript">

    function createTHead() {

        var x = document.getElementById("Table");

        if (!x.tHead) {

            var header = x.createTHead();

            var row = header.insertRow(0);

            var cell = row.insertCell(0);

            cell.innerHTML = "<b>WELCOME TO TABLE HEADER</b>";



    function deleteTHead() {





<body style ="background-color:GREEN">

<table id="Table" border="1">














<br />

<button type="button" onclick="createTHead()">CREATE TABLE HEAD</button>

<button type="button" onclick="deleteTHead()">DELETE TABLE HEAD</button>






when we click on Crete head button


When we click on delete button the recently created header will be disappear.


Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here


More Articles

© 2020 DotNetHeaven. All rights reserved.