How to run a callback function on a jQuery trigger("click")?
When you call trigger
, the bound event handler is immediately executed, so you don't need any callback. Just use
$input.trigger('click');
runtests();
Yes - It is true that trigger doesn't take callback but we can pass callback as parameter.
//.trigger( eventType [, extraParameters ] )
$("#element").bind("customCall", function(e, callback){
callback();
}
var callback = function(){alert("Hello");}
$("#element").trigger("customCall",[callback]);
Hope this will helps
First you need to bind the click event and then you can trigger the click event.
$input.bind('click', function() {
console.log("clicked the input");
});
$input.trigger('click');