Event Web API ¶
English Description ¶
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 <button>, <div>, <span>, 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().