Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
83
rated 0 times [  90] [ 7]  / answers: 1 / hits: 20094  / 13 Years ago, wed, march 14, 2012, 12:00:00

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?


More From » jquery

 Answers
10

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.


[#86846] Tuesday, March 13, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eliasf

Total Points: 703
Total Questions: 97
Total Answers: 129

Location: Chad
Member since Tue, Apr 27, 2021
3 Years ago
;