there's a small difference between the two snippets: in the first one, the element hit
could not be the #myThing
element itself.
Let say that #myThing
is a <p>
and you have clicked on a link inside it: then when the event will reach #myThing
, the element referred by e.target
is the link and not the paragraph
On the contrary, in the second example the element subject to a color change will always be #myThing
So, if you pass the event along with the handler it's because you have a convenience on using that event. When you pass it, you can name it e
or evt
or also foobar
: since you're using jQuery the variable name you choose is not relevant (but for the sake of simplicity e
is short and widely used).
The most common reasons to pass the event usually are
- prevent the default behavior of the event;
- stop the propagation of the event;
- — it's your scenario — deal with the original element in which the event was triggered (often when you're dealing with event delegation or with live update of your document);
- check some of the event properties (e.g.
e.keycode
on keyup/down
event);