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');}
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.
You can trigger a click event on the element by simply running
$('a.pop').click()
$('a.pop').click()
, or if you're triggering some dynamic method, or custom event:
$('a.pop').trigger(eventName)
, e.g: $('a.pop').trigger('click');
Reading from jQuery API, the following should work.
$('a.pop').trigger('click');
.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();
精彩评论