Every event handling function receives an event object, which contains many
properties and methods. The event object is most commonly used to prevent the
default action of the event via the
.preventDefault() method. However, the event
object contains a number of other useful properties and methods, including:
The mouse position at the time the event occurred, relative to the top left of the page.
The type of the event (e.g. "click").
The button or key that was pressed.
Any data that was passed in when the event was bound.
The DOM element that initiated the event.
Prevent the default action of the event (e.g. following a link).
Stop the event from bubbling up to other elements.
In addition to the event object, the event handling function also has access to
the DOM element that the handler was bound to via the keyword
this. To turn
the DOM element into a jQuery object that we can use jQuery methods on, we
$( this ), often following this idiom: