jQuery advantages/differences in .trigger() vs .click()
jquery
Solution
This is the code for the `click` method:
jQuery.fn.click = function (data, fn) {
if (fn == null) {
fn = data;
data = null;
}
return arguments.length > 0 ? this.on("click", null, data, fn) : this.trigger("click");
}
as you can see; if no arguments are passed to the function it will trigger the click event.
Using `.trigger("click")` will call one less function.
And as @Sandeep pointed out in his answer `.trigger("click")` is faster:
As of 1.9.0 the check for `data` and `fn` has been moved to the `.on` function:
$.fn.click = function (data, fn) {
return arguments.length > 0 ? this.on("click", null, data, fn) : this.trigger("click");
}
Problem
In terms of performance, what are the gains (or just differences) between: ``` $('.myEl').click(); ``` and ``` $('.myEl').trigger('click'); ``` Are there any at all?