TIL Check if a given element is in focus
POSTED ON:
TAGS: javascript
The key ingredient is activeElement
const elementIsInFocus = el => (el === document.activeElement);
elementIsInFocus(anyElement)// returns true if in focus, false if not in focus
Related TILs
Tagged: javascript