The onfocusout event occurs when an element is about to lose focus.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.
Definition and Usage
- The onfocusout event occurs when an element is about to lose focus.
- 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.
- Although Firefox does not support the onfocusout event, you can find out whether a child of an element loses focus or not, by using a capturing listener for the onblur event (using the optional useCapture parameter of the addEventListener() method).
- The onfocusout event is the opposite of the onfocusin event.
- The onfocusout event may not work as expected in Chrome, Safari and Opera 15+ using the JavaScript HTML DOM syntax. However, it should work as an HTML attribute and by using the addEventListener() method.
Example
Execute a JavaScript when an input field is about to lose focus:
<input type="text" onfocusout="myFunction()">
Syntax
In HTML :
<element onfocusout="myScript">
In JavaScript :
object.onfocusout = function(){myScript};
In JavaScript, using the addEventListener() method :
object.addEventListener("focusout", myScript);
References :
w3schools