Input Month autofocus Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Month


The autofocus property sets or gets whether a month field should automatically get focus when the page loads, or not.

This property reflects the HTML autofocus attribute.

Set the autofocus property with the following Values

Value Description
true|false Sets whether a month field should get focus when the page loads
  • true - The month field gets focus
  • false - Default. The month field does not get focus

Return Value

A Boolean, returns true if the month field automatically gets focus when the page loads, otherwise it returns false

The following code shows how to check if a month field gets focus upon page load:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<input type="month" id="myMonth" autofocus>

<button onclick="myFunction()">Test</button>

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

function myFunction() {// w ww .  j a v  a2s  .  co m
    var x = document.getElementById("myMonth").autofocus;
    document.getElementById("demo").innerHTML = x;

Related Tutorials