e
is just a parameter name. You can name it however you want to. It will refer to the first argument passed to the function, which in this case will be the event object:
When the browser triggers an event or other JavaScript calls jQuery's .trigger()
method, jQuery passes the handler an event object it can use to analyze and change the status of the event. This object includes a normalized subset of data provided by the browser; the browser's unmodified native event object is available in event.originalEvent
.
What this
refers to depends on how a function is called. In jQuery, this
inside event handlers refers to the element the handler is (logically) bound to:
When jQuery calls a handler, the this
keyword is a reference to the element where the event is being delivered; for directly bound events this is the element where the event was attached and for delegated events this is an element matching selector
. (Note that this may not be equal to event.target
if the event has bubbled from a descendant element.) To create a jQuery object from the element so that it can be used with jQuery methods, use $(this)
.
MDN provides a good explanation of this
in general.
You can find more information in the .on
documentation.
But even so, wouldn't we be able to leave function(e) as function() without the "e"?
Yes of course, in JavaScript you can define functions without parameters, but passing arguments to them won't throw an error.