Cookies improve the way our website works, by using this website you are agreeing to our use of cookies. For more information see our privacy policy.
OK
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.
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 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.
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.
This example illustrates the use of the onblur event:
<head><scripttype="text/javascript">function OnFocusInput (input) {
input.style.color = "red";
}
function OnBlurInput (input) {
input.style.color = "";
}
</script></head><body>
When the following input field has the focus its text color will be red.
Click into the input field!
<br/><br/><inputtype="text"onfocus="OnFocusInput (this)"onblur="OnBlurInput (this)"value="Custom input field"/></body>