Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery on Click event function call

Tags:

jquery

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?

like image 789
David Horák Avatar asked Feb 04 '11 08:02

David Horák


People also ask

How can call Click event on page load in jQuery?

$("document"). ready(function() { setTimeout(function() { $("ul. galleria li:first-child img"). trigger('click'); },10); });

What is $() in jQuery?

$() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements. Most of the time you will need to start with $() function. It is advisable to use jQuery after DOM is loaded fully.


1 Answers

$(".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()});
like image 95
The Scrum Meister Avatar answered Nov 07 '22 08:11

The Scrum Meister