THE EVENT OBJECT
When an event related to the DOM is fired, all of the relevant information is gathered and stored on an object called event
. This object contains basic information such as the element that caused the event, the type of event that occurred, and any other data that may be relevant to the particular event. For example, an event caused by a mouse action generates information about the mouse's position, whereas an event caused by a keyboard action generates information about the keys that were pressed. All browsers support the event
object, though not in the same way.
The DOM Event Object
In DOM-compliant browsers, the event
object is passed in as the sole argument to an event handler. Regardless of the method used to assign the event handler, DOM Level 0 or DOM Level 2, the event
object is passed in. Here is an example which references the event object inside the handler both ways:
let btn = document.getElementById("myBtn");
btn.onclick = function(event...