Javascript Reference - HTML DOM Table tHead Property








The tHead property returns a reference to the <thead> element of a table.

Browser Support

tHead Yes Yes Yes Yes Yes

Syntax

var v = tableObject.tHead

Return Value

A reference to the <thead> element of the table, or null if it is not defined.





Example

The following code shows how to output the innerHTML of <thead>.


<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {<!--   w w w .  jav a2  s  .co  m-->
    border: 1px solid black;
}
</style>
</head>
<body>
<table id="myTable">
   <thead>
     <tr>
       <th>Item</th>
       <th>Price</th>
     </tr>
   </thead>
   <tfoot>
     <tr>
       <td>A</td>
       <td>$1</td>
     </tr>
   </tfoot>
   <tbody>
     <tr>
       <td>B</td>
       <td>$1</td>
     </tr>
   </tbody>
</table><br>

<button onclick="myFunction()">test</button>

<script>
function myFunction() {
    console.log(document.getElementById("myTable").tHead.innerHTML);
}
</script>

</body>
</html>

The code above is rendered as follows: