Javascript DOM HTML Input Range defaultValue Property

Introduction

Get the default value of a slider control:

var x = document.getElementById("myRange").defaultValue;

Click the button to display the default of the slider control.

View in separate window

<!DOCTYPE html>
<html>
<body>

Points: <input type="range" id="myRange" value="20">
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from  w  w w. j av  a  2  s. com
  var x = document.getElementById("myRange").defaultValue;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The defaultValue property sets or gets the default value of a slider control.

The default value is the value set in the HTML value attribute.

The defaultValue contains the default value, while value contains the current value.

If there are no changes, defaultValue and value is the same.

ItemDescription
value Specifies the default value of the slider control
Return Value A String, representing the default value of the slider control



PreviousNext

Related