Javascript DOM HTML Table createTFoot() Method

Introduction

Create a <tfoot> element (and insert a <tr> and <td> element to it):

Click the button to create a tfoot element for the table.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, td {
  border: 1px solid black;
}
</style>//from  w w w .j  av a  2  s . co  m
</head>
<body>
<table id="myTable">
  <tr>
    <td>cell 1</td>
    <td>cell 2</td>
  </tr>
  <tr>
    <td>cell 3</td>
    <td>cell 4</td>
  </tr>
</table>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
  var table = document.getElementById("myTable");
  var footer = table.createTFoot();
  var row = footer.insertRow(0);
  var cell = row.insertCell(0);
  cell.innerHTML = "<b>This is a table footer</b>";
}
</script>

</body>
</html>

The createTFoot() method creates an empty <tfoot> element and adds it to the table.

If a <tfoot> element exists on the table, the createTFoot() method returns the existing one, and does not create a new one.

The <tfoot> element must have one or more <tr> tags inside.

The createTFoot() method returns the newly created or an existing <tfoot> element.




PreviousNext

Related