How do you tell if an input or textarea has focus in native javascript?
This is not a duplicate as it asks for a native Javascript solution!
To determine if any input/textarea on the page has focus:
if([...document.querySelectorAll("input, textarea")].some(el => el === document.activeElement)) {
// An input or textarea currently has focus
}
To determine if a particular input/textarea on the page has focus:
if(document.activeElement === textareaEl) {
// textareaEl currently has focus
}
jQuerytag should have not been added, I've just removed that tag.