Select autofocus attribute

Definition and usage

autofocus Whether the dropdown list should automatically gain focus when the page is loaded.

This attribute reflects HTML autofocus attribute.

See also:

HTML-referenshandbok:HTML <select>-tag

Example

Determine 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 - Dropdown list has gained focus
  • false - Default. Dropdown list has not gained focus

Tekniska detaljer

Returvärde: Boolsk värde, om rullgardinslistan automatiskt får fokus när sidan laddas, returneras true; annars returneras false.

Webbläsarstöd

Numrerna i tabellen anger den första webbläsarens version som helt stöder detta attribut.

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Stöd 10.0 Stöd Stöd Stöd

Relaterade sidor

HTML-referenshandbok:HTML <select> autofocus-attribut