Javascript Reference - HTML DOM Input Month autofocus Property








The autofocus property sets or gets if a month field can auto focus when the page loads.

Browser Support

autofocus Yes No No Yes Yes

Syntax

Return the autofocus property.

var v = monthObject.autofocus 

Set the autofocus property.

monthObject.autofocus=true|false

Property Values

Value Description
true|false Set if a month field can auto focus when the page loads
  • true - The month field gets focus
  • false - Default. The month field does not get focus




Return Value

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

Example

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


<!DOCTYPE html>
<html>
<body>
<!--  w  w w . j ava  2 s .  com-->
<input type="month" id="myMonth" autofocus>
<button onclick="myFunction()">test</button>

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

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

</body>
</html>

The code above is rendered as follows: