HTML DOM Document activeElement

Example

Get the currently focused element:

const element = document.activeElement.tagName;
Try it Yourself »

Description

The activeElement property returns the HTML element that have focus.

The activeElement property is read-only.


Syntax

document.activeElement

Return Value

Type Description
ElementThe HTML element that has focus

Browser Support

document.activeElement is a DOM Level 1 (1998) feature.

It is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 9-11


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.