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.