Latest web development tutorials

HTML DOM focus () method

Elements Object Reference Element object

Examples

Sets focus for <a> elements:

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

try it"

Definitions and use

focus () method is used to set the focus (if set) for the element.

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


Browser Support

方法
focus() Yes Yes Yes Yes Yes

grammar

HTMLElementObject .focus ()

parameter

None

Technical Description

return value: No return value

Examples

More examples

Examples

Sets focus for a text field:

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

try it"

Examples

After the document is loaded, set the focus to a text field:

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

try it"

Related Pages

HTML DOM Reference Manual: the onfocus event


Elements Object Reference Element object