Javascript DOM HTML Input Month autofocus Property get

Introduction

Find out if a month field automatically gets focus on page load:

var x = document.getElementById("myMonth").autofocus;

Click the button to find out if the month field automatically gets focus on page load.

input elements with type=month is not supported in Firefox.

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="month" id="myMonth" autofocus>
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*w  ww. j av a2  s . c  o m*/
  var x = document.getElementById("myMonth").autofocus;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The autofocus property sets or gets whether a month field 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 month field gets focus
false Default. The month field does not get focus

The autofocus property returns true if the month field automatically gets focus on page load, otherwise it returns false.




PreviousNext

Related