Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript blur event -- is there any way to detect which element now has focus? [duplicate]

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

like image 675
morgancodes Avatar asked Feb 09 '09 13:02

morgancodes


People also ask

What is the difference between focus and blur events?

The blur event fires when an element has lost focus. The event does not bubble, but the related focusout event that follows does bubble. The opposite of blur is the focus event, which fires when the element has received focus. The blur event is not cancelable.

Which Javascript event is called when an element loses focus?

The focusout event fires when an element has lost focus, after the blur event. The two events differ in that focusout bubbles, while blur does not. The opposite of focusout is the focusin event, which fires when the element has received focus.

What is the difference between Onblur and onChange?

onChange is when something within a field changes eg, you write something in a text input. onBlur is when you take focus away from a field eg, you were writing in a text input and you have clicked off it.


1 Answers

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

like image 69
Gary Green Avatar answered Oct 29 '22 23:10

Gary Green