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?
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?
- 3 How to pass params: stackoverflow.com/questions/3273350/… – user800014 Commented Mar 14, 2012 at 15:45
- No. e in that context is the event object that is populated when the event callback is executed. What are you trying to do? – Austin Brunkhorst Commented Mar 14, 2012 at 15:46
- @sergio-michels pls write your comment as answer - I'll mark it as best. – xander27 Commented Mar 14, 2012 at 15:48
- @xander27 ok, posted as answer :) – user800014 Commented Mar 14, 2012 at 16:07
2 Answers
Reset to default 11Here, 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.
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.