HTML DOM activeElementProperty
Examples
The element that currently has focus:
var x = document.activeElement.tagName;
xThe output result is:
BUTTON
Try it yourself »
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 theelement.focus()method.
Tip:You can use thedocument.hasFocus()method to check whether the current element has focus.
Browser Support
The numbers in the table indicate the first browser version that supports this property.
| Property | |||||
|---|---|---|---|---|---|
| activeElement | 2.0 | 4.0 | 3.0 | 4.0 | 9.6 |
Syntax
document.activeElement
Technical Details
| Return Value: | The element that currently has focus |
|---|
Other Extensions
Document Object