jQuery advantages/differences in .trigger() vs .click()

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");
}

Leave a Comment