contactmatt
contactmatt

Reputation: 18600

Javascript/JQuery event arguments. I don't understand what this 'e' argument is or does

JQuery:

this.saveButton.click(function (e) {
    scope.saveForm();
});

This is a very simple line of JQuery that binds the .click() event to the saveButton object and calls a saveForm function when the event is fired.

When this event is called, what is 'e'? I don't think it is ever used.

Upvotes: 0

Views: 4154

Answers (4)

Przemek
Przemek

Reputation: 6700

e (or any other name you use) is an Event object. It is very useful when you, for example want to determine where did the click event take place or which key was pressed on keydown event.

You should read this article on jQuery API.

Example usage:

$("#someInput").keydown(function (e) {
  alert(e.which) // alerts the keycode of the pressed key
});

Upvotes: 0

asawyer
asawyer

Reputation: 17808

It's the event object. Take a look at the documentation page here:

http://api.jquery.com/click/

Upvotes: 2

Justin Niessner
Justin Niessner

Reputation: 245419

Event handlers can take an optional parameter that contains information about the event that occurred. In this case, it is unused.

Upvotes: 1

Blazemonger
Blazemonger

Reputation: 92893

The e can be used to obtain specific information about the click (left, right or center; coordinates clicked; DOM object clicked on), but this specific code sample doesn't use it.

See http://api.jquery.com/category/events/event-object/ for details about what's available.

Upvotes: 4

Related Questions