Themans

What's the Easiest Way to Check Which Elements Are On Focus?

Asked by Themans 2 years ago elements on focus


Pablo G
0
 
When we use old JavaScript (without any frameworks) this is what we get:

Var focusedElement;

document.addEventListener("focus", function(e) {
    focusedElement = e.target;
}, true);

document.addEventListener("blur", function(e) {
    focusedElement = null;
}, true);

Whenever an element gains focus, then we save that element to a variable, and when the element loses focus, we reset the variable.

Does this help?

by Pablo G 2 years ago

Answer this question

What's the Easiest Way to Check Which Elements Are On Focus?

0 errors found:

 
0