11

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?

3
  • 3
    try $(".menu_link").click(GetContentAndSlide); Commented Feb 4, 2011 at 8:38
  • @clyde-lobo It is legal to post a solution as a answer. Commented Feb 4, 2011 at 8:40
  • @"The Scrum Meister" : yup i know that... just posted it in a hurry.By the time i realized it.you had already answered it ;) Commented Feb 4, 2011 at 8:42

2 Answers 2

20
$(".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()});
Sign up to request clarification or add additional context in comments.

Comments

0

Strangely, .click didn't work for me.

What worked was

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.