Object: Event
The Event object represents provides contextual information about an event that Event handlers can use, such as the originating element, what stage the event is currently in within the event system, and so forth.
The properties and methods exposed by Event are minimal, and provide the basic functionality required by events of all types. More specific event objects should be used to acquire context information specific to a certain event type.
For example, the MouseEvent object, which inherits from Event through the UIEvent object, supplies additional properties supplying information such as the MouseEvent.button, MouseEvent.screenX and MouseEvent.screenY for where the current mouse event took place.
Event properties
Property name |
Type |
Description |
Status |
Availability |
|---|---|---|---|---|
bubbles |
boolean |
When true, the event is a bubbling event. |
read only |
4.6. or later |
cancelable |
boolean |
When true, the action of the event can be cancelled using Event.preventDefault() . |
read only |
4.6. or later |
cancelBubble |
boolean |
When true, bubbling of the event is cancelled. |
writable |
4.6. or later |
currentTarget |
EventTarget |
The node of the Document object that is currently handling the event. |
read only |
4.6. or later |
eventPhase |
unsigned short |
The phase that the event is currently in. Valid values include: |
read only |
4.6. or later |
target |
EventTarget |
The target node to which the event was dispatched. |
read only |
4.6. or later |
timeStamp |
unsigned long |
The time (in milliseconds since epoch) at which the event was created. |
read only |
4.6 or later |
type |
String |
The name of the event. |
read only |
4.6 or later |
Event methods
Method name |
Description |
Availability |
|---|---|---|
Initializes the properties of an Event object created by Document.createEvent(). |
4.6 or later |
|
Cancels the event, preventing the default action from occurring. |
4.6 or later |
|
Prevents further propagation of this event during an event flow. |
4.6 or later |
Method: Event.initEvent()
The initEvent() method initializes the properties of an Event object created by Document.createEvent(). This method must be called before the event has been dispatched using Node.dispatchEvent().
Parameters
Parameter |
Type |
Description |
|---|---|---|
eventTypeArge |
String |
Specifies the event type. |
canBubbleArg |
boolean |
When true, this parameter indicates that the event will bubble. |
cancelableArg |
boolean |
When true, this parameter indicates that Event.preventDefault() can cancel the event. |
Method: Event.preventDefault()
Method: Event.stopPropagation()
The stopPropagation() method prevents further propagation of this event during an event flow. If this method is called by any EventListener, the event will no longer propagate through the tree. The event will complete the dispatch to all listeners on the current EventTarget before the event flow stops.
This method can be used at any stage of the event flow.