, , , , , , , , and
Event Onfocusout
[ Event Object](#)
## Example
Execute JavaScript when the input field is about to lose focus:
[Try it Β»](#)
More examples are included at the bottom of this chapter.
* * *
## Definition and Usage
The onfocusout event occurs when an element is about to lose focus.
**Note:** The onfocusout event is similar to the (#) event. The main difference is that the onblur event does not bubble. Therefore, if you need to check whether an element or its child element loses focus, you need to use the onfocusout event.
**Note:** Although Firefox does not support the onfocusout event, you can use the capture listener event of (#) (using the optional _useCapture_ parameter of the addEventListener() method) to check whether an element or its child element loses focus.
**Note:** The opposite event of the onfocusout event is the (#) event.
* * *
## Browser Support
| Event | | | | | |
| --- | --- | --- | --- | --- | --- |
| onfocusout | Yes | Yes | Yes | Yes | Yes |
**Note:** The onfocusin event using HTML DOM syntax may not work correctly in Chrome, Safari, and Opera 15+ browsers. However, as an HTML element, it works correctly using the addEventListener() method.
* * *
## Syntax
In HTML:
(#)
In JavaScript (may not work in Chrome, Safari, and Opera 15+):
_object_.onfocusout=function(){_myScript_};(#)
In JavaScript, using the addEventListener() method:
_object_.addEventListener("focusout", _myScript_);(#)
**Note:** Internet Explorer 8 and earlier versions of IE do not support the [addEventListener()](#) method.
* * *
## Technical Details
| Bubbles: | Yes |
| --- |
| Cancelable: | No |
| Event type: | FocusEvent |
| Supported HTML tags: | All HTML elements, except: , ,
, , , , , , , , and |
* * *

## More Examples
## Example
Using the "onfocusin" and "onfocusout" events:
[Try it Β»](#)
## Example
Event Delegation: Setting the _useCapture_ parameter of addEventListener() to true (for focus and blur):
var x = document.getElementById("myForm");
x.addEventListener("focus", myFocusFunction, **true**);
x.addEventListener("blur", myBlurFunction, **true**);
function myFocusFunction() {
document.getElementById("myInput").style.backgroundColor = "yellow";
}
function myBlurFunction() {
document.getElementById("myInput").style.backgroundColor = "";
}
[Try it Β»](#)
## Example
Event Delegation: Using the focusout event (not supported in Firefox):
var x = document.getElementById("myForm");
x.addEventListener("focusin", myFocusFunction);
x.addEventListener("focusout", myBlurFunction);
function myFocusFunction() {
document.getElementById("myInput").style.backgroundColor = "yellow";
}
function myBlurFunction() {
document.getElementById("myInput").style.backgroundColor = "";
}
[Try it Β»](#)
* * Event Object](#)
, , , , , , , , and
YouTip