A data-* attribute on a <tfoot> tag attaches additional data to the table footer.
To create a custom attribute, replace * with a lowercase string, such as data-id
, data-status
, or data-location
.
A custom data-description
attribute on a <tfoot> tag.
The attribute value is not visible, but is readable by JavaScript.
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 data-description="Total number of finalist">
<tr>
<td colspan="2">Number of finalists: 3</td>
</tr>
</tfoot>
</table>
The data-* attribute adds custom information to a <tfoot> element.
The * part is replaced with a lowercase string, such as data-id, data-cost, or data-location.
An <tfoot> element can have any number of data-* attributes, each with their own name.
Using data-* attributes reduces the need for requests to the server.
Note: The data-* attribute is not visible and does not change the appearance of the tfoot.
<tfoot data-*="value">
Note: The * can be any string, such as data-id
, data-cost
, data-supplier
, etc.
Value | Description |
---|---|
value | A string value. Can be numeric, alphanumeric, JSON, etc. |
A custom data-description
attribute on a <tfoot> tag.
Clicking the button will display the description value.
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="mytfoot" data-description="Total count of finalists">
<tr>
<td colspan="2">Number of finalists: 3</td>
</tr>
</tfoot>
</table>
<br/>
<button onclick="show();">Show data</button>
<script>
let show = () => {
let element = document.getElementById("mytfoot");
alert("Description = " + element.getAttribute('data-description'));
}
</script>
The <tfoot> tag has a custom data-description
attribute.
The data-description
attribute describes what type of information is located inside the <tfoot>.
Clicks are handled by the onclick
event.
Onclick invokes a JavaScript function that extracts and displays the <tfoot> description.
Note: Notice how the description displays immediately without server call.
Here is when data-* 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>