Input Time autofocus Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Time


The autofocus property sets or gets whether a time field 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 time field should get focus when the page loads
  • true - The time field gets focus
  • false - Default. The time field does not get focus

Return Value

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

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<input type="time" id="myTime" autofocus>

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

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

function myFunction() {/* w w  w. j  a  va 2  s . c om*/
    var x = document.getElementById("myTime").autofocus;
    document.getElementById("demo").innerHTML = x;


Related Tutorials