Easy Tutorial
❮ Prop Style Flexwrap Prop Style Margintop ❯

HTML DOM focus() Method

Element Object

Example

Set focus to an <a> element:

document.getElementById("myAnchor").focus();

Definition and Usage

The focus() method is used to set focus to an element (if it can be focused).

Tip: Use the blur() method to remove focus from an element.


Browser Support

Method
focus() Yes Yes Yes Yes Yes

Syntax

Parameters

| None |

Technical Description

| Return Value: | No return value | | --- | --- |


More Examples

Example

Set focus to a text field:

document.getElementById("myText").focus();

Example

Set focus to a text field after the document loads:

window.onload = function() {   
    document.getElementById("myText").focus();};

Related Pages

HTML DOM Reference: onfocus Event


Element Object

❮ Prop Style Flexwrap Prop Style Margintop ❯