9

Can I pass an additional parameter to this function?

$("#foold").click( function(e) {
  // CODE
};

For example, I need to pass some X value to this function. Can I write something like this:

<a href="javascript:void(X)" id="fooId">Foo</a>

to pass value in this function through e or some other way?

Justin ᚅᚔᚈᚄᚒᚔ
  • 14,744
  • 6
  • 50
  • 63
xander27
  • 2,875
  • 8
  • 29
  • 38

2 Answers2

11

Here, e is an event object, as defined here: http://api.jquery.com/category/events/event-object/

Yes you can pass data to the handler, using this form for the click function:

.click( [eventData], handler(eventObject) )

eventData             A map of data that will be passed to the event handler.
handler(eventObject)  A function to execute each time the event is triggered.

It will be accessible as e.data in the handler.

SirDarius
  • 39,072
  • 8
  • 82
  • 98
1

In this link you can see how to pass params to the JQuery click function jQuery's .click - pass parameters to user function

Basically

It allows you to pass a data map to the event object that automatically gets fed back to the event handler function by jQuery as the first parameter.

Community
  • 1
  • 1