An id on a <tfoot> tag assigns an identifier to the table footer.
The identifier must be unique across the page.
An id attribute on a <tfoot> element.
First Name | Last Name |
---|---|
Denice | Hobermann |
Paulo | Cornell |
Jane | Hollander |
Number of finalists: 3 |
<style>
table.tb { width: 250px; border-collapse: collapse; }
.tb th, .tb td { border: solid 1px #777; padding: 5px; }
.tb th { text-align: center; }
.tb tfoot { background-color:lightblue; }
</style>
<table class="tb">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Denice</td>
<td>Hobermann</td>
</tr>
<tr>
<td>Paulo</td>
<td>Cornell</td>
</tr>
<tr>
<td>Jane</td>
<td>Hollander</td>
</tr>
</tbody>
<tfoot id="finalist-counter">
<tr>
<td colspan="2">Number of finalists: 3</td>
</tr>
</tfoot>
</table>
The id attribute assigns an identifier to the <tfoot> element.
The id allows JavaScript to easily access the <tfoot> element.
It is also used to point to a specific id selector in a style sheet.
Tip: id is a global attribute that can be applied to any HTML element.
<tfoot id="identifier" />
Value | Description |
---|---|
identifier | A unique alphanumeric string. The id value must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.). |
A <tfoot> element with a unique id.
Clicking the button displays the number of rows in the table footer.
First Name | Last Name |
---|---|
Denice | Hobermann |
Paulo | Cornell |
Jane | Hollander |
Number of finalists: 3 |
<style>
table.tbl { width: 250px; border-collapse: collapse; }
.tbl th, .tbl td { border: solid 1px #777; padding: 5px; }
.tbl th { text-align: center; }
.tbl tfoot { background-color:lightblue; }
</style>
<table class="tbl">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Denice</td>
<td>Hobermann</td>
</tr>
<tr>
<td>Paulo</td>
<td>Cornell</td>
</tr>
<tr>
<td>Jane</td>
<td>Hollander</td>
</tr>
</tbody>
<tfoot id="mytfoot">
<tr>
<td colspan="2">Number of finalists: 3</td>
</tr>
</tfoot>
</table>
<br />
<button onclick="show();">Show # tfoot rows</button>
<script>
let show = () => {
let element = document.getElementById("mytfoot");
let rowCount = element.getElementsByTagName("tr").length;
alert("# Rows = " + rowCount);
}
</script>
The id attribute assigns a unique identifier for the <tfoot>.
Clicking the button calls JavaScript which locates the <tfoot> through the id.
It then counts the number of <tr> (table rows) inside the <tfoot> and displays it in an alert box.
Here is when id support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |
Back to <tfoot>