Easy Tutorial
❮ Prop Textarea Readonly Prop Fileupload Type ❯

autofocus Attribute

Input Text Object Reference

Example

Check if the text field automatically gains focus after the page loads:

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

x returns:

true

Definition and Usage

The autofocus attribute is used to set or return whether the text field automatically gains focus when the page loads.

This attribute reflects the HTML autofocus attribute.


Browser Support

All major browsers support the autofocus attribute.

Note: Internet Explorer 9 and earlier versions or Opera 12 and earlier versions do not support the autofocus attribute.


Syntax

Return the autofocus attribute:

Set the autofocus attribute:

Attribute Values

Value Description
true false Describes whether the text field gains focus after the page loads<br> true - The text field gains focus<br> false - Default. The text field does not gain focus

| Return Value: | Boolean, returns true if the text field automatically gains focus after the page loads, otherwise returns false. | | --- | --- |


Related Pages

HTML Reference: HTML <input> autofocus Attribute


❮ Prop Textarea Readonly Prop Fileupload Type ❯