Events
Modern browsers can trigger hundreds of types of events (~500).
https://developer.mozilla.org/en-US/docs/Web/Events
These event types can be of any kind:
User interaction : click, input change, keypress, drag & drop etc...
Geolocation,
Device motion,
Network status,
...
Registering Event Listeners
These events can be intercepted by adding an event listener to the corresponding event type.
An event listener is a JavaScript function that will be called whenever the event is triggered.
In most cases, the listener function will take as first argument, the event object with different properties and data depending on the event type and the event itself.
Listening to a click
Listening to keyboard
Watching geolocation
Some functions like watchPosition
will prompt the user for his consent before allowing access to geolocation.
Removing Event Listeners
In order to avoid side effects, dead code and memory leaks it is important to think about clearing your event registrations by removing the listeners.
This can be done differently depending on the event type.
removeEventListener
removeEventListener
clear...
clear...
Events bubbling & capturing
Last updated