A data-* attribute on a <progress> tag attaches additional data to the progress element.
To create a custom attribute, replace * with a lowercase string, such as data-id
, data-status
, or data-location
.
A custom data-for
attribute on a <progress> bar.
The attribute value is not visible, but it is readable by JavaScript.
<div>Loading files... </div>
<progress data-for="progress of file loading" value="50" max="100"> 50% </progress>
The data-* attribute adds custom information to a <progress> element.
The * part is replaced with a lowercase string, such as data-id, data-cost, or data-location.
An <progress> 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 progress.
<progress 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-total
attribute on a <progress> element.
Clicking the button will display the total value.
<div>Processing invoices... </div>
<progress id="myprogress" data-total="1702 records" value="50" max="100"> 50% </progress>
<br/>
<button onclick="show();">Show data</button>
<script>
let show = () => {
let element = document.getElementById("myprogress");
alert("Total = " + element.getAttribute('data-total'));
}
</script>
The <progress> tag has a custom data-total
attribute.
The data-total
attribute describes the total of the <progress>.
Clicks are handled by the onclick
event.
Onclick invokes a JavaScript function that extracts and displays the <progress> total.
Note: Notice how the progress purpose displays immediately without server call.
Here is when data-* support started for each browser:
Chrome
|
8.0 | Dec 2010 |
Firefox
|
16.0 | Oct 2012 |
IE/Edge
|
10.0 | Sep 2012 |
Opera
|
11.0 | Dec 2010 |
Safari
|
6.0 | Jul 2012 |
Back to <progress>