An id on a <meter> tag assigns an identifier to the meter.
The identifier must be unique across the page.
An id attribute on a <meter> element.
<div>Loading files...</div>
<br />
<meter id="load-meter" value="0.5">50%</meter>
The id attribute assigns an identifier to the <meter> element.
The id allows JavaScript to easily access the <meter> 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.
<meter 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 <meter> element with a unique id.
Clicking the button displays the meter value.
<div>Loading files...</div>
<br />
<meter id="mymeter" value="0.35">35%</meter>
<br /><br />
<button onclick="show();">Show meter value</button>
<script>
let show = () => {
let element = document.getElementById("mymeter");
alert("Value = " + element.value);
}
</script>
The id attribute assigns a unique identifier for the <meter>.
Clicking the button calls JavaScript which locates the <meter> using the id.
Finally, the <meter> value is displayed in an alert box.
Here is when id 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>