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 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

Event - 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

Event - Missed Event

Management

Type

The type of an event categorize the event. It's also known as the name of the event (Ref)

Example:

List

DOM - Event Type (name)

Category

Event - Category

See

In the chrome devtool

Devtool Chrome Event Listener

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

Javascript Event Targets (DOM)

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

Task Runner