The HTML DOM Input Time autofocus property sets/returns whether Input Time is focused upon initial page load.
Syntax
Following is the syntax −
- Returning boolean value - true/false
inputTimeObject.autofocus
- Setting autofocus to booleanValue
inputTimeObject.autofocus = booleanValue
Boolean Values
Here, “booleanValue” can be the following:
| booleanValue | Details |
|---|---|
| true | It defines that input will be autofocused on initial page load. |
| false | It is the default value and input is not autofocused. |
Example
Let us see an example of Input Time autofocus property −
<!DOCTYPE html>
<html>
<head>
<title>Input Time autofocus</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>Time-autofocus</legend>
<label for="TimeSelect">Exam Time:
<input type="time" id="TimeSelect" value="10:00" autofocus>
</label>
<input type="button" onclick="removeAutofocus()" value="Remove Autofocus">
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputTime = document.getElementById("TimeSelect");
divDisplay.textContent = 'Autofocus: '+inputTime.autofocus;
function removeAutofocus() {
inputTime.autofocus = false;
divDisplay.textContent = 'Autofocus: '+inputTime.autofocus;
}
</script>
</body>
</html>Output
This will produce the following output −
Before clicking ’Remove Autofocus’ button −

After clicking ‘Remove Autofocus’ button −
