May 2019
Beginner to intermediate
650 pages
14h 50m
English
DOM events are asynchronous notifications issued by the operating system and propagated by the browser. Events are commonly triggered by an action performed by the user (for example, a mouse click), but they can also be called programmatically (for example, calling the click() method from any DOM target) or dispatched as a configurable synchronous operation (for example, calling dispatchEvent() on a DOM target).
DOM targets usually register as event listeners using their addEventListener() method. The following code registers a click listener for all the <rect> elements in a page (see Events/1-element-handler.html):
const rects = [...document.getElementsByTagName("rect")];rects.forEach(d => d.addEventListener('click', handler)); ...Read now
Unlock full access