Javascript DOM HTML Table deleteTHead() Method

Introduction

Remove a <thead> element from a table:

document.getElementById("myTable").deleteTHead();

Click the button to remove the thead element from the table.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>/*ww w.  ja v  a  2 s .c  om*/
</head>
<body>
<table id="myTable">
  <thead>
    <tr>
      <th>Month</th>
      <th>Savings</th>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <td>Sum</td>
      <td>$180</td>
    </tr>
  </tfoot>
  <tbody>
    <tr>
      <td>January</td>
      <td>$100</td>
    </tr>
    <tr>
      <td>February</td>
      <td>$180</td>
    </tr>
  </tbody>
</table>
<br>

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

<script>
function myFunction() {
  document.getElementById("myTable").deleteTHead();
}
</script>

</body>
</html>

The deleteTHead() method removes the <thead> element from the table.




PreviousNext

Related