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

HTML DOM Input Search autofocus Property

Input Search autofocus Property

Input Search Object Reference Input Search Object

Example

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

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

x

The output is:

true

Try it »


Definition and Usage

The autofocus property sets or returns whether the search 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 property

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


Syntax

Return the autofocus attribute:

searchObject

.autofocus

Set the autofocus attribute:

searchObject

.autofocus=true|false

Attribute values

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

    Technical Details

    Return Value: A Boolean value that returns true if the search field automatically gets focus after the page loads, otherwise returns false.

    Related pages

    HTML Reference Manual: HTML autofocus attribute


    Input Search Object Reference Input Search Object