Javascript Reference - HTML DOM Input Number step Property








The step property sets or gets the step attribute of a number field.

The step attribute sets the number intervals for a number field.

If step="3", the numbers could be -3, 0, 3, 6, etc.

Browser Support

step Yes 10.0 Yes Yes Yes

Syntax

Return the step property.

var v = numberObject.step

Set the step property.

numberObject.step=number




Property Values

Value Description
number Set the number intervals. Default is 1

Return Value

A String type value representing the number intervals for the number field.

Example

The following code shows how to change the number intervals for a number field.


<!DOCTYPE html>
<html>
<body>
Number:<!--  ww w  .j  a va2 s .com-->
<input type="number" id="myNumber" step="3">
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myNumber").step = "5";
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the number intervals for a number field.


<!DOCTYPE html>
<html>
<body>
<!--from  w w w. j  av  a2s .  co  m-->
Number:
<input type="number" id="myNumber" step="3">
<button onclick="myFunction()">test</button>

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

<script>
function myFunction() {
    var x = document.getElementById("myNumber").step;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: