Find out if a slider control automatically gets focus on page load:
var x = document.getElementById("myRange").autofocus;
Click the button to find out if the slider control automatically gets focus on page load.
<!DOCTYPE html> <html> <body> <input type="range" id="myRange" autofocus> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w w w .j a v a 2 s .c o m*/ var x = document.getElementById("myRange").autofocus; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The autofocus property sets or gets whether a slider control should automatically get focus on page load.
This property mirrors the HTML autofocus attribute.
The autofocus property accepts and returns a boolean type value.
Value | Description |
---|---|
true | The slider control gets focus |
false | Default. The slider control does not get focus |
The autofocus property returns true if the slider control automatically gets focus on page load, otherwise it returns false.