Table createTFoot() method

Definition and Usage

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

Note:If there is already an <tfoot> element in the table, then createTFoot() The method returns the existing element without creating a new one.

Note:The <tfoot> element must contain one or more <tr> tags.

Tip:To remove the <tfoot> element from the table, use deleteTFoot() method.

See also:

HTML Reference Manual:HTML <tfoot> Tag

Instance

Example 1

Create <tfoot> element (and insert <tr> and <td> elements into it):

// Find the <table> element with id="myTable":
var table = document.getElementById("myTable");
// Create an empty <tfoot> element and add it to the table:
var footer = table.createTFoot();
// Create an empty <tr> element and add it to the first position of <tfoot>:
var row = footer.insertRow(0);      
// Insert a new cell (<td>) at the first position of the "new" <tr> element:
var cell = row.insertCell(0);
// Add bold text to the new cell:
cell.innerHTML = "<b>This is a table footer</b>";

Try It Yourself

Example 2

Create and delete <tfoot> elements:

function myCreateFunction() {
  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>";
}
function myDeleteFunction() {
  document.getElementById("myTable").deleteTFoot();
}

Try It Yourself

Syntax

tableObject.createTFoot()

Parameters

None.

Technical Details

Return Value: Newly created (or existing)<tfoot> Element.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support