onblurEvent
Examples
Execute a piece of JavaScript code when the user leaves the input field:
<input type="text" onblur="myFunction()">
Try it Yourself »
Definition and Usage
The onblur event occurs when an object loses focus.
Onblur is often used for JavaScript validation code, generally for form input fields.
Tip:The opposite event of onblur is theonfocusevent.
Syntax
In HTML:
<element
onblur="SomeJavaScriptCode">
In JavaScript:
object.onblur=function(){SomeJavaScriptCode};
| Parameters | Description |
|---|---|
| SomeJavaScriptCode | Required. Specifies the JavaScript to execute when the event occurs. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the onblur event
HTML tags that support the onblur event:
The onblur attribute can apply to all HTML elements, except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>.
Event Object Other Extensions