Textarea autofocus attribute

Definition and Usage

autofocus Attribute sets or returns whether the text area 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

Check if the text area automatically gains focus when the page is loaded:

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

Try it yourself

Syntax

Return the autofocus attribute:

textareaObject.autofocus

Set the autofocus attribute:

textareaObject.autofocus = true|false

attribute value

value description
true|false

Specifies whether the text area should gain focus when the page loads

  • true - The text area gains focus
  • false - Default. The text area does not gain focus

Technical Details

Return Value: Boolean value, returned if the text area automatically gains focus when the page loads true; otherwise return false

Browser Support

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