Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Input Text autofocus property

Input Text autofocus property

Input Text Object Reference Input Text object reference

Example

Check whether the text field automatically gets focus after the page loads:

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

x The returned result is:

true

Try it »


Definition and Usage

The autofocus property is used to set or return whether the text field automatically gets focus after the page loads.

This attribute reflects the HTML autofocus attribute.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the autofocus attribute.

**Note:** Internet Explorer 9 and earlier IE versions, or Opera 12 and earlier versions of browsers, do not support the autofocus property.


Syntax

Return the autofocus property:

textObject

.autofocus

Set the autofocus property:

textObject

.autofocus=true|false

Attribute values

Value Description
true|false Describes whether the text field gets focus after the page loads
  • true - the text field gets focus
  • false - default. the text field does not get focus
  • |

    Technical Details

    Return value: Boolean, returns true if the text field automatically gets focus after the page loads, otherwise returns false.

    Related pages

    HTML Reference Manual: HTML autofocus attribute


    Input Text Object Reference The Input Text object