The onblur
property of the GlobalEventHandlers
mixin is the EventHandler
for processing blur
events. It's available on Element
, Document
, and Window
.
The blur
event is raised when an element loses focus.
Note: The opposite of onblur
is onfocus
.
target.onblur = functionRef;
functionRef
is a function name or a function expression. The function receives a FocusEvent
object as its sole argument.
This example uses onblur
and onfocus
to change the text within an <input>
element.
<input type="text" value="CLICK HERE">
let input = document.querySelector('input');
input.onblur = inputBlur;
input.onfocus = inputFocus;
function inputBlur() {
input.value = 'Focus has been lost';
}
function inputFocus() {
input.value = 'Focus is here';
}
Try clicking in and out of the form field, and watch its contents change accordingly.
Specification | Status | Comment |
HTML Living StandardThe definition of 'onblur' in that specification. | Living Standard |
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Android webview | Chrome for Android | Firefox for Android | Opera for Android | Safari on iOS | Samsung Internet | |
onblur
|
Chrome
Full support Yes |
Edge
Full support 12 |
Firefox
Full support Yes |
IE
Full support Yes |
Opera
Full support Yes |
Safari
Full support Yes |
WebView Android
Full support Yes |
Chrome Android
Full support Yes |
Firefox Android
Full support Yes |
Opera Android
Full support Yes |
Safari iOS
Full support Yes |
Samsung Internet Android
Full support Yes |
In contrast to IE, in which almost all kinds of elements receive the blur
event, only a few kinds of elements on Gecko browsers work with this event.
blur
eventGlobalEventHandlers.onfocus
GlobalEventHandlers.onblur by Mozilla Contributors is licensed under CC-BY-SA 2.5.