Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h2>How to Access a thead Element</h2>
<table>
 <thead id="myTHead">
   <tr>
     <th>Header 1</th>
     <th>Header 2</th>
   </tr>
  </thead>
 <tbody>
   <tr>
     <td>Cell 1</td>
     <td>Cell 2</td>
   </tr>
   <tr>
     <td>Cell 3</td>
     <td>Cell 4</td>
   </tr>
  </tbody>
</table>
<p>Click "Try it" to change the style of the thead element.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
  const element = document.getElementById("myTHead");
  element.style.color = "red";
}
</script>
</body>
</html>