Latest web development tutorials

HTML DOM Input Text autofocus attribute

Input Text Object Reference Input Text Object Reference

Examples

Check whether the text field automatically get the focus when the page is loaded:

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

x returns the result as follows:

true

try it"


Definition and Usage

autofocus property sets or returns whether a page of text fields automatically get focus when loaded.

This property reflects the HTML autofocus property.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the autofocus attribute.

Note: Internet Explorer 9 and earlier versions of IE or Opera 12 and earlier versions of the browser does not support autofocus attribute.


grammar

Back autofocus properties:

textObject .autofocus

Setting autofocus properties:

textObject .autofocus = true | false

Property Value

value description
true | false It describes whether the text field gets focus after the page is loaded
  • true - text field gets focus
  • false - default. Text field does not get the focus
technical details
return value: Boolean value, if the text field after the page loads automatically get the focus returns true, otherwise returns false.


Related Pages

HTML Reference Manual: HTML <the INPUT> The autofocus attribute


Input Text Object Reference Input Text Object