onfocusout event
Example
Execute JavaScript when the input box is about to lose focus:
Try it »
More examples are included at the bottom of this section.
Definition and Usage
The onfocusout event is triggered when an element is about to lose focus.
**Tip:** The onfocusout event is similar to onblur the event. The main difference is that the onblur event does not support bubbling. Therefore, if you need to check whether an element or its child elements get focus, you need to use the onfocusout event.
Tip: Although Firefox does not support the onfocusout event, you can use the onfocus (using the optional parameter of the addEventListener() method) useCapture(using the optional parameter of the addEventListener() method) capture listener event to check whether the element or its child elements lose focus.
Tip: The opposite event of onfocusout is onfocusin events.
Browser support
| Events | |||||
|---|---|---|---|---|---|
| onfocusout | Yes | Yes | Yes | Yes | Yes |
Note: In Chrome, Safari and Opera 15+ browsers, the onfocusin event using HTML DOM syntax may not work properly. However, as an HTML element, it works properly by using the addEventListener() method.
Syntax
In HTML:
<
element
onfocusout="
myScript
">Try it
In JavaScript (Chrome, Safari and Opera 15+ may not work properly):
object
.onfocusout=function(){
myScript
};
Try it
In JavaScript, use the addEventListener() method:
object
.addEventListener("focusout",
myScript
);
Try it
Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.
Technical Details
| Does it support bubbling: | Yes |
|---|---|
| Is it cancelable: | No |
| Event type: | FocusEvent |
| Supported HTML tags: | All HTML elements, except: , , , |
Event Object