THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML DOM activeElement Property

Document Object Reference Document Object

Example

Get the currently focused element in the document:

var x = document.activeElement.tagName;

The result of x could be:

BUTTON
Try it Yourself »

Definition and Usage

The activeElement property returns the currently focused element in the document.

Note: This property is read-only.

Tip: To give focus to an element, use the element.focus() method.

Tip: To find out if the document has focus, use the document.hasFocus() method.


Browser Support

The numbers in the table specify the first browser version that fully supports the property.

Property
activeElement 2.0 4.0 3.0 4.0 9.6

Note: For iOS, elements that are not text input elements will not get focus assigned to them. The property will then be body or null.


Syntax

document.activeElement

Technical Details

Return Value: A reference to the element object in the document that has focus

Document Object Reference Document Object