Javascript Reference - HTML DOM Progress Object








The Progress object represents an HTML <progress> element.

The <progress> element represents the progress of a task.

Progress Object Properties

Property Description
labels Returns a list of the progress bar's labels (if any)
max Sets or gets the value of the max attribute of a progress bar
position Returns the current position of the progress bar
value Sets or gets the value of the value attribute of a progress bar

Standard Properties and Events

The Progress object supports the standard properties and events.

Example

We can access a <progress> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<progress id="myProgress" value="75" max="100"></progress>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from   w ww  .  jav  a  2s. c  o  m-->
    var x = document.getElementById("myProgress").value;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

We can create a <progress> element by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from  w w  w.j a va  2  s. c om-->
    var x = document.createElement("PROGRESS");
    x.setAttribute("value", "25");
    x.setAttribute("max", "100");
    document.body.appendChild(x);
}
</script>
</body>
</html>

The code above is rendered as follows: