HTML DOM activeElement Property
Example
Get the currently focused element in the document:
var x = document.activeElement.tagName;
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 <input type="text">, will not get focus assigned to them. The property will then return BODY or null.
Syntax
document.activeElement
Technical Details
Return Value: | A reference to the element object in the document that has focus |
---|