Information About What Happened
When an event fires, the browser automatically creates an event object and passes it as the first argument to your handler function. This object contains all the details about what just occurred.
elem.addEventListener('click', function(event) {
console.log(event.type); // "click" — the type of event
console.log(event.currentTarget); // the element the handler is attached to
console.log(event.clientX + ':' + event.clientY); // cursor coordinates in the window
});
Key Properties
| Property | Description |
|---|---|
event.type | The event name (e.g., "click", "keydown") |
event.target | The deepest element that was actually clicked |
event.currentTarget | The element the handler is bound to (same as this inside the handler) |
event.clientX / clientY | Mouse cursor coordinates relative to the browser window |
event.timeStamp | When the event occurred (milliseconds since page load) |
Note
The target property points to the innermost element the user actually clicked. currentTarget points to the element where the event handler is registered. They differ when events bubble up the DOM tree.