Javascript Reference - HTML DOM Input Range autofocus Property








The autofocus property sets or gets whether a slider control can auto focus when the page loads.

Browser Support

autofocus Yes 10.0 Yes Yes Yes

Syntax

Return the autofocus property.

var v = rangeObject.autofocus 

Set the autofocus property.

rangeObject.autofocus=true|false

Property Values

Value Description
true|false Set whether a slider control can auto focus when the page loads
  • true - The slider control gets focus
  • false - Default. The slider control does not get focus




Return Value

A Boolean type value, true if the slider control automatically gets focus when the page loads, otherwise false.

Example

The following code shows how to check if a slider control can auto focus upon page load.


<!DOCTYPE html>
<html>
<body>
<input type="range" id="myRange" autofocus>
<button onclick="myFunction()">test</button>
<!--from   w  w  w . j a  v  a2  s  . c om-->
<p id="demo"></p>

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

</body>
</html>

The code above is rendered as follows: