shrewdbeans shrewdbeans - 1 year ago 68
Javascript Question

In Javascript/jQuery what does (e) mean?

I am new to JavaScript/jQuery and I've been learning how to make functions. A lot of functions have cropped up with (e) in brackets. Let me show you what I mean:

$(this).click(function(e) {
// does something

It always appears that the function doesn't even use the value of (e), so why is it there so often?

Answer Source

e is the short var reference for event object which will be passed to event handlers.

The event object essentially has lot of interesting methods and properties that can be used in the event handlers.

In the example you have posted is a click handler which is a MouseEvent

$(<element selector>).click(function(e) {
    // does something
    alert(e.type); //will return you click

DEMO - Mouse Events DEMO uses e.which and e.type

Some useful references:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download