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.
The focusout event is not cancelable.
Syntax
Use the event name in methods like addEventListener().
addEventListener("focusout", (event) => {});
Event type
Event properties
This interface also inherits properties from its parent UIEvent, and indirectly from Event.
-
FocusEvent.relatedTarget
-
The element receiving focus, if any.
Examples
Live example
HTML
<form id="form">
<label>
Some text:
<input type="text" placeholder="text input" />
</label>
<label>
Password:
<input type="password" placeholder="password" />
</label>
</form>
JavaScript
const form = document.getElementById("form");
form.addEventListener("focusin", (event) => {
event.target.style.background = "pink";
});
form.addEventListener("focusout", (event) => {
event.target.style.background = "";
});
Result
Specifications
Note: The UI Events specification describes an order of focus events that's different from what current browsers implement.
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
focusout_event |
1 |
12 |
52 |
9 |
11.6 |
5 |
≤37 |
18 |
52 |
12.1 |
4.2 |
1.0 |
See also