Reputation: 5565
I would like to call a function from the jQuery Click event. I tried the annotation below which doesn't work.
$(".menu_link").click(GetContentAndSlide());
What is the right annotation?
Upvotes: 11
Views: 24838
Reputation: 1894
Strangely, .click didn't work for me.
What worked was
$(".menu_link").on('click', GetContentAndSlide);
Upvotes: 0
Reputation: 30111
$(".menu_link").click(GetContentAndSlide);
remove the ()
, you are executing the function, instead of passing the function reference.
Another option would be (in case your function uses the this
pointer) to wrap it around with a anonymous function:
$(".menu_link").click(function() {GetContentAndSlide()});
Upvotes: 20