You are here: Reference > JavaScript > client-side > event handling > events > ondeactivate

ondeactivate event | deactivate event

Browser support:
Occurs on the active element when it loses the active state.
Only one element can be active at a time in a document. An active element does not necessarily have focus, but an element with focus is always the active element in a document. For example, an active element within a window that is not the foreground window has no focus.
  • 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.
The ondeactivate event is not cancelable. If you want to prevent an element from losing the focus, cancel the onbeforedeactivate event. For further details and for a cross-browser solution, please see the page for the onbeforedeactivate event.
To detect when an element becomes active, use the onbeforeactivate, onactivate and DOMActivate events.

How to register:

<ELEMENT ondeactivate="handler">

In JavaScript:
object.ondeactivate = handler;
object.addEventListener ("deactivate", handler, useCapture);
object.attachEvent ("ondeactivate", 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.
For a complete list of events, see the page for Events in JavaScript.

Basic information:

Bubbles Yes
Cancelable No
Event object UIEvent

Actions that invoke the ondeactivate event:

  • Clicking outside the active element.
  • Navigating away from the active element with the TAB or an access key.
  • 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 ondeactivate event:

Action Event order
Any action that invokes the ondeactivate event.
  1. onbeforedeactivate
  2. ondeactivate
  3. onfocusout
  4. onblur

Example HTML code 1:

This example illustrates the use of the ondeactivate event:
    <script type="text/javascript">
        function OnActivateForm (event) {
   = "red";
        function OnDeActivateForm (event) {
   = "";

    Click on the text fields to see the result!
    <form onactivate="OnActivateForm (event)" ondeactivate="OnDeActivateForm (event)">
        User name: <input type="text" value="my name"/><br />
        E-mail: <input type="text" value=""/>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content