onblur event
Example
Execute a piece of JavaScript code when the user leaves the input box:
Try it »
Definition and Usage
The onblur event occurs when an object loses focus.
Onblur is often used in JavaScript validation code, generally for form input fields.
**Tip:** The opposite event of onblur is the event. onfocus event.
Syntax
In HTML:
<
element
onblur="
SomeJavaScriptCode
">In JavaScript:
object
.onblur=function(){
SomeJavaScriptCode
};
| Parameters | Description |
|---|---|
| SomeJavaScriptCode | Required. Specifies the JavaScript to be executed when the event occurs. |
Browser support





All major browsers support the onblur event
HTML tags that support the onblur event:
The onblur attribute can be applied to all HTML elements, except:
, , ,
Event Object