Find out if a datetime field automatically gets focus on page load:
var x = document.getElementById("myDatetime").autofocus;
Click the button to find out if the datetime field automatically gets focus on page load.
input elements with type="datetime" is supported by Safari.
<!DOCTYPE html> <html> <body> <input type="datetime" id="myDatetime" autofocus> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from www . j av a 2s . co m var x = document.getElementById("myDatetime").autofocus; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The autofocus property sets or gets whether a datetime field should automatically get focus on page load, or not.
This property mirrors the HTML autofocus attribute.
The <input type="datetime"> element is supported by Safari.
Property Values
Value | Description |
---|---|
true | The datetime field gets focus |
false | Default. The datetime field does not get focus |
The autofocus property returns true if the datetime field automatically gets focus on page load, otherwise it returns false.