Input Search autofocus Attribute

Definition and Usage

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

This attribute reflects the HTML autofocus attribute.

See also:

HTML Reference Manual:HTML <input> autofocus Attribute

Example

Determine if the search field will automatically gain focus when the page is loaded:

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

Try it yourself

Syntax

Return autofocus attribute:

searchObject.autofocus

Set autofocus attribute:

searchObject.autofocus = true|false

Attribute value

Value Description
true|false

Define whether the search field should gain focus when the page is loaded.

  • true - The search field receives focus
  • false - Default. The search field does not receive focus

Technical Details

Return Value: Boolean value, returned if the search field automatically receives focus when the page is loaded true; otherwise return false.

Browser Support

The numbers in the table indicate the first browser version that fully supports this attribute.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support