- Event
- Interfaces based on Event
- Constructor
- Instance properties
- Legacy and non-standard properties
- Instance methods
- Deprecated methods
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- Event: returnValue property
- Value
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- Event.returnValue
- Syntax
- Specifications
- Browser compatibility
- returnValue property (event)
Event
The Event interface represents an event which takes place in the DOM.
An event can be triggered by the user action e.g. clicking the mouse button or tapping keyboard, or generated by APIs to represent the progress of an asynchronous task. It can also be triggered programmatically, such as by calling the HTMLElement.click() method of an element, or by defining the event, then sending it to a specified target using EventTarget.dispatchEvent() .
There are many types of events, some of which use other interfaces based on the main Event interface. Event itself contains the properties and methods which are common to all events.
Many DOM elements can be set up to accept (or «listen» for) these events, and execute code in response to process (or «handle») them. Event-handlers are usually connected (or «attached») to various HTML elements (such as , , , etc.) using EventTarget.addEventListener() , and this generally replaces using the old HTML event handler attributes. Further, when properly added, such handlers can also be disconnected if needed using removeEventListener() .
Note: One element can have several such handlers, even for the exact same event—particularly if separate, independent code modules attach them, each for its own independent purposes. (For example, a webpage with an advertising-module and statistics-module both monitoring video-watching.)
When there are many nested elements, each with its own handler(s), event processing can become very complicated—especially where a parent element receives the very same event as its child elements because «spatially» they overlap so the event technically occurs in both, and the processing order of such events depends on the Event bubbling and capture settings of each handler triggered.
Interfaces based on Event
Below is a list of interfaces which are based on the main Event interface, with links to their respective documentation in the MDN API reference.
Note that all event interfaces have names which end in «Event».
- AnimationEvent
- AudioProcessingEvent Deprecated
- BeforeUnloadEvent
- BlobEvent
- ClipboardEvent
- CloseEvent
- CompositionEvent
- CustomEvent
- DeviceMotionEvent
- DeviceOrientationEvent
- DragEvent
- ErrorEvent
- FetchEvent
- FocusEvent
- FontFaceSetLoadEvent
- FormDataEvent
- GamepadEvent
- HashChangeEvent
- HIDInputReportEvent
- IDBVersionChangeEvent
- InputEvent
- KeyboardEvent
- MediaStreamEvent Deprecated
- MessageEvent
- MouseEvent
- MutationEvent Deprecated
- OfflineAudioCompletionEvent
- PageTransitionEvent
- PaymentRequestUpdateEvent
- PointerEvent
- PopStateEvent
- ProgressEvent
- RTCDataChannelEvent
- RTCPeerConnectionIceEvent
- StorageEvent
- SubmitEvent
- SVGEvent Deprecated
- TimeEvent
- TouchEvent
- TrackEvent
- TransitionEvent
- UIEvent
- WebGLContextEvent
- WheelEvent
Constructor
Creates an Event object, returning it to the caller.
Instance properties
A boolean value indicating whether or not the event bubbles up through the DOM.
A boolean value indicating whether the event is cancelable.
A boolean indicating whether or not the event can bubble across the boundary between the shadow DOM and the regular DOM.
A reference to the currently registered target for the event. This is the object to which the event is currently slated to be sent. It’s possible this has been changed along the way through retargeting.
Indicates whether or not the call to event.preventDefault() canceled the event.
Indicates which phase of the event flow is being processed. It is one of the following numbers: NONE , CAPTURING_PHASE , AT_TARGET , BUBBLING_PHASE .
Indicates whether or not the event was initiated by the browser (after a user click, for instance) or by a script (using an event creation method, for example).
A reference to the object to which the event was originally dispatched.
The time at which the event was created (in milliseconds). By specification, this value is time since epoch—but in reality, browsers’ definitions vary. In addition, work is underway to change this to be a DOMHighResTimeStamp instead.
The name identifying the type of the event.
Legacy and non-standard properties
A historical alias to Event.stopPropagation() that should be used instead. Setting its value to true before returning from an event handler prevents propagation of the event.
The explicit original target of the event.
The original target of the event, before any retargetings.
A historical property still supported in order to ensure existing sites continue to work. Use Event.preventDefault() and Event.defaultPrevented instead.
A boolean value indicating whether the given event will bubble across through the shadow root into the standard DOM. Use composed instead.
Instance methods
Returns the event’s path (an array of objects on which listeners will be invoked). This does not include nodes in shadow trees if the shadow root was created with its ShadowRoot.mode closed.
Cancels the event (if it is cancelable).
For this particular event, prevent all other listeners from being called. This includes listeners attached to the same element as well as those attached to elements that will be traversed later (during the capture phase, for instance).
Stops the propagation of events further along in the DOM.
Deprecated methods
Initializes the value of an Event created. If the event has already been dispatched, this method does nothing. Use the constructor ( Event() instead).
Specifications
Browser compatibility
BCD tables only load in the browser
See also
- Types of events available: Event reference
- Comparison of Event Targets ( target vs. currentTarget vs. relatedTarget vs. originalTarget )
- Creating and triggering custom events
Found a content problem with this page?
This page was last modified on Jul 3, 2023 by MDN contributors.
Your blueprint for a better internet.
Event: returnValue property
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
The Event property returnValue indicates whether the default action for this event has been prevented or not.
It is set to true by default, allowing the default action to occur. Setting this property to false prevents the default action.
Note: While returnValue has been adopted into the DOM standard, it is present primarily to support existing code. Use preventDefault() , and defaultPrevented instead of this historical property.
Value
A boolean value which is true if the event has not been canceled; otherwise, if the event has been canceled or the default has been prevented, the value is false .
The value of returnValue is the opposite of the value returned by defaultPrevented .
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Apr 7, 2023 by MDN contributors.
Your blueprint for a better internet.
Event.returnValue
Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.
Deprecated
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Avoid using it and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
The Event.returnValue property indicates if the default action for this event has been prevented or not. It is set to true by default, allowing the default action to occur. Setting this property to false prevents the default action.
Syntax
event.returnValue = bool; var bool = event.returnValue;
Specifications
Although it was included in an old Working Draft of W3C DOM Level 2, this property is not part of any specification. Microsoft also has a description of it on MSDN.
Browser compatibility
Feature | Firefox (Gecko) | Chrome | Edge | Internet Explorer | Microsoft Edge | Opera | Safari |
---|---|---|---|---|---|---|---|
Basic support | No support | (Yes) | (Yes) | 6 | (Yes) | (Yes) | (Yes) |
Feature | Firefox Mobile (Gecko) | Android | Edge | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | No support | (Yes) | (Yes) | ? | ? | (Yes) |
returnValue property (event)
You can get whether an event can be canceled with the cancelable property in all browsers except in Internet Explorer before version 9. Although the cancelable property exists in Firefox, it always returns true, regardless of the cancelable state of the event. There is no way to determine whether an event can be canceled in Internet Explorer before version 9.
If an event is cancelable, you can use the preventDefault method and the returnValue property to cancel the event. When an event is canceled, the default action that belongs to the event will not be executed. For example, when the onclick event (the onclick event is cancelable) is canceled for a checkbox, then clicking on the checkbox does not change its checked state.
Note that the use of the preventDefault method and the returnValue property on a non-cancelable event does not cause an error. When an event handler returns false, the event will be canceled. You can use it instead of the preventDefault method and the returnValue property. See Example 2 below.
Note that Internet Explorer from version 9 started to support different event objects similarly to Firefox, Opera, Google Chrome and Safari. The event object passed to an event handler and the event object referred to by the window.event property are different in Internet Explorer from version 9 (except if the event handler is registered with the attachEvent method). The returnValue property is only supported by the window.event object.
The properties and methods mentioned above do not affect the propagation of events. If you need to prevent the propagation of an event in the DOM hierarchy, use the cancelBubble property or the stopPropagation method.