Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In web browsers, what's the difference between onblur and onfocusout?

If they're the same, then why there are two of this kind of event?

like image 327
lovespring Avatar asked Oct 13 '11 13:10

lovespring


People also ask

What is difference between Onblur and Onfocusout?

The onfocusout event occurs when an element is about to lose focus. Tip: The onfocusout event is similar to the onblur event. The main difference is that the onblur event does not bubble. Therefore, if you want to find out whether an element or its child loses focus, you should use the onfocusout event.

What is Onblur used for?

Definition and Usage The onblur attribute fires the moment that the element loses focus. Onblur is most often used with form validation code (e.g. when the user leaves a form field). Tip: The onblur attribute is the opposite of the onfocus attribute.

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.

What is the difference between focus and Focusin?

The focusin event fires when an element is about to receive focus. The main difference between this event and focus is that focusin bubbles while focus does not. The opposite of focusin is focusout .


2 Answers

As you know, the onBlur event fires for an element if that element had the focus, but loses it.

The onFocusOut event fires in this case, but also triggers if any child element loses focus.

For example, you have a div with special formatting because the human is currently editing a field in that area. You'd could use onFocusOut to turn that formatting off when focus leaves that div.

Up until very recently, onFocusOut was only used by IE. If that has changed, it has been very recent. Test in FF, Chrome, etc.

like image 103
Patrick Karcher Avatar answered Sep 22 '22 02:09

Patrick Karcher


Acccording to the spec for the focusout event type:

This event type is similar to blur, but is dispatched before focus is shifted, and does bubble.

Whereas blur events do bubble, and are dispatched later.

like image 34
Luc125 Avatar answered Sep 24 '22 02:09

Luc125