Does anyone have a technique that will allow me to determine which element has focus after a blur
event? I have an input field which I'd like to reset on blur
unless the blur
was caused by the user clicking the save button. I'd love to just set a flag in the save button's onclick
function, but that would fire too late (unless click
events always fire before blur
events, which I doubt.)
Asked
Active
Viewed 9,656 times
8

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

morgancodes
- 25,055
- 38
- 135
- 187
-
On the other subject I saw only hacks, but there's actually a builtin solution very easy to use : https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement Basically you can capture the focus element like this: `const focusedElement = document.activeElement` and you're good to go – Thomas J. Aug 28 '17 at 14:04