An id on a <progress> tag assigns an identifier to the element.
The identifier must be unique across the page.
An id attribute on a <progress> element.
<div>Loading files... </div>
<progress id="load-progress" value="50" max="100"> 50% </progress>
The id attribute assigns an identifier to the <progress> element.
The id allows JavaScript to easily access the <progress> 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.
<progress 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 <progress> element with a unique id attribute. The element is loading from 0 to 100% repeatedly. Clicking the button displays the current progress value.
<div>Loading files... </div>
<progress id="myprogress" max="100" value="50"> 50% </progress>
<br />
<button onclick="show();">Show progress value</button>
<script>
setInterval( function(){
let value = document.getElementById("myprogress").value;
value = Math.min(value + .1, 100) % 100;
document.getElementById("myprogress").value = value;
}, 10 );
let show = () => {
let element = document.getElementById("myprogress");
alert("Value = " + parseInt(element.value));
}
</script>
The id attribute assigns a unique identifier for the <progress>.
JavaScript locates the <progress> using the id.
It then increases the value of the <progress> by 1 each 10 milliseconds.
Here is when id 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>