A data-* attribute on a <meter> tag attaches additional data to the meter element.
To create a custom attribute, replace * with a lowercase string, such as data-id
, data-status
, or data-location
.
A custom data-estimate
attribute on a <meter> element.
The attribute value is not visible, but it is readable by JavaScript.
<div>Calculating interest...</div>
<br />
<meter value="0.2" data-estimate="May take 10 minutes...">20%</meter>
The data-* attribute adds custom information to a <meter> element.
The * part is replaced with a lowercase string, such as data-id, data-cost, or data-location.
An <meter> 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 meter.
<meter 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-size
attribute on a <meter> tag.
Clicking the button will display the size value.
<div>Uploading documents...</div>
<br />
<meter id="mymeter" value="0.5" data-size="3.87 TB">50%</meter>
<br/><br/>
<button onclick="show();">Show data</button>
<script>
let show = () => {
let element = document.getElementById("mymeter");
alert("Size = " + element.getAttribute('data-size'));
}
</script>
The <meter> tag has a custom data-size
attribute.
The total files size of the <meter> is stored in the data-size
.
Clicks are handled by the onclick
event.
Onclick invokes a JavaScript function that extracts and displays the attribute value.
Note: Notice how the meter usage displays immediately without server call.
Here is when data-* support started for each browser:
Chrome
|
8.0 | Dec 2010 |
Firefox
|
6.0 | Aug 2011 |
IE/Edge
|
13.0 | Nov 2015 |
Opera
|
11.0 | Dec 2010 |
Safari
|
6.0 | Jul 2012 |
Back to <meter>