Reputation: 25
function AAA(i){console.log(i);}
$('div').click({i:'clicked'},AAA);
How do I pass a parameter/data into the function when using .click()? the above does not work.
Upvotes: 1
Views: 90
Reputation: 15393
An optional object of data passed to an event method when the current executing handler is bound.
function AAA(event){
console.log(event.data.i);
}
$('div').click({i:'clicked'},AAA);
Upvotes: 1
Reputation: 318182
The data passed in is available as event.data
inside the event handlers callback function
function AAA(event){
console.log( event.data.i );
}
$('div').click({i:'clicked'}, AAA);
Upvotes: 4