8

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.)

BenMorel
  • 31,815
  • 47
  • 169
  • 296
morgancodes
  • 24,623
  • 37
  • 132
  • 186
  • 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

1 Answers1

5

Answered here; When onblur occurs, how can I find out which element focus went to?

Community
  • 1
  • 1
Gary Green
  • 21,457
  • 6
  • 48
  • 75