DOM - Event
About
This section is about the management of action in the Document object model (ie in the browser)
An event allows for signaling that something has occurred, e.g., that an image has completed downloading.
Event are code structures that listen out for things happening to the document.
In the DOM specification, you can find the following:
- The type of an event
- The concept of a regular event parent and a cross-boundary event parent
The callback function that handle the event can be created with the help of:
- An event handler. Its name starts with “on” and is followed by the name of the event for which it is intended. (Example: onClick)
and get back an event object
Features
The following features are defined in the DOM Events specification:
- MouseEvent interface
- MouseEventInit dictionary type
- The UIEvent interface's detail attribute
An event's type is synonymous of name type (ie “an event named click” or “if the event name is keypress”)
Example
For example, the following document fragment:
<button class="btn btn-info" onclick="console.log('Bouh!')" >Click Me</button>
Glossary
In the contexts of events, the terms fire and dispatch are used as defined in the DOM specification:
Fire
Dispatch
Dispatching an event means to follow the steps that propagate the event through the tree.
Trusted
The term trusted event is used to refer to events whose isTrusted attribute is initialized to true
Missed
Management
Type
The type of an event categorize the event. It's also known as the name of the event (Ref)
Example:
List
Category
See
In the chrome devtool
Propagation (Bubble)
An event may bubble (ie propagate) up the dom tree to other subscriber.
Prevent default
If you don't want to have the default behavior (such as following a link), you can prevent it (stop it)
Target
Object
The structure of an event can be found in the Event interface definition.
Create your own
You can also create your own event type. See How to create your own custom event type (Javascript, DOM)?
Documentation / Reference
- Document Object Model (DOM) Level 2 Events, T. Pixley. W3C.
- Document Object Model (DOM) Level 3 Events Specification, T. Leithead, J. Rossi, D. Schepers, B. Höhrmann, P. Le Hégaret, T. Pixley. W3C.
- Progress Events, A. van Kesteren, C. McCathie Nevile; J. Song. W3C. An event interface that can be used for measuring progress; e.g. HTTP entity body transfers