Input Range autofocus Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Range

Description

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

This property reflects the HTML autofocus attribute.

Set the autofocus property with the following Values

Value Description
true|false Sets whether a slider control should get focus when the page loads

Return Value

A Boolean, returns true if the slider control gets focus when the page loads, otherwise it returns false

The following code shows how to check if a slider control gets focus upon page load:

Demo Code

ResultView the demo in separate window

<!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  .  com
    var x = document.getElementById("myRange").autofocus;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials