Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM activeElement property

HTML DOM activeElement property

Document Object Reference Document Object

Example

The element that currently has focus:

var

x = document.activeElement.tagName;

x The output is:

BUTTON

Try it


Definition and usage

The activeElement property returns the element that currently has focus in the document.

Note: This property is read-only.

Tip: To set focus on an element, you can use element.focus() method.

Tip: You can use document.hasFocus() method to check whether the current element has focus.


Browser support

The numbers in the table indicate the version number of the first browser that supports this property.

property
activeElement 2.0 4.0 3.0 4.0 9.6

Syntax

document.activeElement

Technical description

Return value: The element that currently has focus

Document Object Reference Document Object