Select autofocus attribute

Definition and usage

autofocus Property settings or returns whether the dropdown list should automatically gain focus when the page is loaded.

This attribute reflects HTML autofocus attribute.

See also:

HTML reference manual:HTML <select> tag

Example

Find out if the dropdown list will automatically gain focus when the page is loaded:

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

Try it yourself

Syntax

Return autofocus attribute:

selectObject.autofocus

Set autofocus attribute:

selectObject.autofocus = true|false

Attribute value

Value Description
true|false

Specify whether the dropdown list should gain focus when the page is loaded.

  • true - The dropdown list has gained focus
  • false - Default. The dropdown list has not gained focus

Technical details

Return value: Boolean value, returns true if the dropdown list automatically receives focus when the page is loaded; otherwise, returns false.

Browser support

The numbers in the table indicate the first browser version to fully support this attribute.

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

Related pages

HTML reference manual:HTML <select> autofocus attribute