onblur event | blur event
Occurs when an element loses focus.
An element with focus is always the active element in a document, but an active element does not necessarily have focus. For example, an active element within a window that is not the foreground window has no focus. Only one element can be active at a time in a document.The onblur event is not cancelable. If you want to prevent the deactivation of an element, cancel the onbeforedeactivate event. For a detailed description, see the page for onbeforedeactivate event.
- You can get the active element with the activeElement property.
- To set the active element in a document, use the focus and setActive methods.
- To determine whether the active element has focus, use the hasFocus method.
To detect when an element receives focus, use the onfocusin, DOMFocusIn and onfocus events.
How to register:
|object.onblur = handler;|
|object.addEventListener ("blur", handler, useCapture);|
|object.attachEvent ("onblur", handler);|
You can find the related objects in the Supported by objects section below.
The event object is accessible to all event handlers in all browsers. The properties of the event object contain additional information about the current event. To get further details about these properties and the possible event handler registration methods, please see the page for the event object.
Actions that invoke the onblur event:
- Clicking outside the active element.
- Navigating away from the active element with the TAB or an access key.
- Switching to another document or application.
- Invoking the setActive method on a non-active element that can be active.
- Invoking the focus method on a non-active element that can be active.
- Invoking the blur method on the active element.
The order of events related to the onblur event:
|Switching to another document or application.||
|Any other action that invokes the onblur event.||
Example HTML code 1:
This example illustrates the use of the onblur event:
Did you find this example helpful?
Supported by objects:
a, abbr, acronym, address, applet, area, b, bdo, big, blockquote, body, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, listing, map, marquee, menu, nobr, noframes, object, ol, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
User Contributed Comments