1

I want to trigger this jquery function by using trigger method of JQuery. How can I do that ? Actually I dont even know the trigger method is suitable for user defined functions.

$('a.pop').click(function() {alert('testing'); }

this is not working

 $('a').trigger(testtt);

 var testtt = function(){ alert('aaa');} 

5 Answers 5

1

Very similar to the way you install the event handler:

$('a.pop').click();

If you have the name of the event you want to trigger as a string, you can also do it this way:

$('a.pop').trigger('click');

This is also the solution to use if you want to pass crafted data to the event handler -- trigger also accepts a second parameter.

Sign up to request clarification or add additional context in comments.

Comments

1

You can trigger a click event on the element by simply running

$('a.pop').click()

Comments

1

$('a.pop').click(), or if you're triggering some dynamic method, or custom event:

$('a.pop').trigger(eventName), e.g: $('a.pop').trigger('click');

Comments

0

Reading from jQuery API, the following should work.

$('a.pop').trigger('click');

Comments

0

.trigger() is used to trigger event handlers (custom or built-in'). Since you bound your function to the "click" handler, you can use trigger like so to call it:

$('a.pop').trigger('click');

jQuery's event binding methods can also be called without parameters to trigger them, which means you can also do this:

$('a.pop').click();

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.