Input Datetime autofocus attribute

Definition and usage

autofocus Attribute sets or returns whether the date and time field should automatically gain focus when the page is loaded.

This property reflects the HTML autofocus attribute.

See also:

HTML reference manual:HTML <input> autofocus egenskap

Example

Find out if the date and time field automatically gains focus when the page is loaded:

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

Try it yourself

Syntax

Return autofocus attribute:

datetimeObject.autofocus

Set autofocus attribute:

datetimeObject.autofocus = true|false

Attribute value

Value Description
true|false

Specify whether the date and time field should gain focus when the page is loaded.

  • true - The date and time field gains focus
  • false - Default. The date and time field does not gain focus

Technical details

Return value: Boolean value, if the date and time field automatically focuses when the page is loaded, it returns true, annars returneras false.

Webbläsarstöd

Numrerna i tabellen anger den första webbläsarversionen som helt stöder denna egenskap.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Stöd 10.0 Stöd Stöd Stöd

Observera:Elementet <input type="datetime"> visar ingen datum- och tidsfält/kalender i alla vanliga webbläsare utom Safari.