Phong Duong

🔎Search

Get currently focused element

24-03-2021 | #javascript

To get the currently focused element, you retrieve the activeElement property of the document

document.activeElement

It returns the element which currently has focus, body or null if there is no focused element.

The property will return the input or textarea element if it has the text selection.

Share: TwitterFacebookLinkedInHacker News