A data-* attribute on a <footer> tag attaches additional data to the footer.
To create a custom attribute, replace * with a lowercase string, such as data-id
, data-status
, or data-location
.
A custom data-year-published
attribute on a <footer>.
The attribute value is not visible, but it is readable by JavaScript.
<footer data-year-published="2020">
<p>© Company, Ltd. All Rights Reserved.</p>
</footer>
The data-* attribute allows you to add custom attributes to a <footer> element.
The * part is replaced with a lowercase string, such as data-id, data-cost, or data-location.
An <footer> element can have any number of data-* attributes, each with their own name.
These attributes usually store additional data about the footer (e.g. id, options, variations, etc.).
Using data-* attributes reduces the need for Ajax requests to the server.
Note: The data-* attribute does not change the appearance of the footer tag in any way.
<footer 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-published-year
attribute is assigned to a <footer> element.
Clicking the button will display the year.
<footer id="myfooter" data-published-year="2020">
<p>© Company, Ltd. All Rights Reserved.</p>
</footer>
<br/>
<button onclick="show();">Show data</button>
<script>
let show = () => {
let element = document.getElementById("myfooter");
alert("Year published = " + element.getAttribute('data-published-year'));
}
</script>
The <footer> tag is assigned the data-published-year
attribute.
The data-published-year
attribute specifies the page publication year.
Button clicks are handled by the onclick
event.
Onclick invokes a JavaScript function that extracts and displays the page publication year.
Note: Notice how the year displays immediately without server call.
Here is when data-* support started for each browser:
Chrome
|
6.0 | Sep 2010 |
Firefox
|
4.0 | Mar 2011 |
IE/Edge
|
9.0 | Mar 2011 |
Opera
|
11.1 | Mar 2011 |
Safari
|
5.0 | Jun 2010 |
Back to <footer>