Javascript DOM HTML Input Time autofocus Property

Introduction

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

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

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

View in separate window

<!DOCTYPE html>
<html>
<body>

<input type="time" id="myTime" autofocus>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from  ww w .j  av  a  2 s .  com*/
  var x = document.getElementById("myTime").autofocus;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The autofocus property sets or gets whether a time field should automatically get focus on page load.

This property mirrors the HTML autofocus attribute.

The <input type="time"> element is not supported in Firefox.

Value Description
true The time field gets focus
false Default. The time field does not get focus

The autofocus property returns true if the time field automatically gets focus when the page loads, otherwise it returns false.




PreviousNext

Related