Latest web development tutorials

HTML DOM Input Search autofocus attribute

Input Search Object Reference Input Search Object

Examples

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

var x = document.getElementById ( "mySearch") autofocus.;
x The output is:
true

try it"

Definition and Usage

autofocus property sets or returns whether to automatically search field get the focus when the page loads.

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 or earlier version of Opera browser does not support autofocus attribute.


grammar

Back autofocus properties:

searchObject .autofocus

Setting autofocus properties:

searchObject .autofocus = true | false

Property Value

value description
true | false It describes the search field after the page is loaded whether to acquire focus
  • true - the search field gets focus
  • false - default. Search field does not get focus

technical details

return value: Boolean value, if the page is the search field get the focus automatically after loading returns true, otherwise returns false.


Related Pages

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


Input Search Object Reference Input Search Object