David Horák
David Horák

Reputation: 5565

JQuery on Click event function call

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

Answers (2)

Cătălin Rădoi
Cătălin Rădoi

Reputation: 1894

Strangely, .click didn't work for me.

What worked was

$(".menu_link").on('click', GetContentAndSlide);

Upvotes: 0

The Scrum Meister
The Scrum Meister

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

Related Questions