I am trying to call a function with parameters using jQuery's .click, but I can't get it to work.
This is how I want it to work:
$('.leadtoscore').click(add_event('shot'));
which calls
function add_event(event) {
blah blah blah }
It works if I don't use parameters, like this:
$('.leadtoscore').click(add_event);
function add_event() {
blah blah blah }
But I need to be able to pass a parameter through to my add_event
function.
How can I do this specific thing?
I know I can use .click(function() { blah }
, but I call the add_event
function from multiple places and want to do it this way.
I had success using .on() like so:
Then inside the
add_event
function you get access to 'shot' like this:See the .on() documentation for more info, where they provide the following example: