Javascript Reference - HTML DOM Input Time focus() Method








The focus() method sets focus to a time field.

Browser Support

The focus() method is supported in all major browsers.

focus Yes Yes Yes Yes Yes

Syntax

timeObject.focus() 

Parameters

None.

Return Value

No return value

Example

The following code shows how to set focus to a time field.


<!DOCTYPE html>
<html>
<body>
<!--from  w  w w .  jav  a2 s . co m-->
<input type="time" id="myTime" value="22:15:00">
<button type="button" onclick="getFocus()">Get focus</button>
<button type="button" onclick="loseFocus()">Lose focus</button>

<script>
function getFocus() {
    document.getElementById("myTime").focus();
}

function loseFocus() {
    document.getElementById("myTime").blur();
}
</script>

</body>
</html>

The code above is rendered as follows: