7

I'm looking for the difference in performance between those two, I could not found in SSE no good answer about this topic.

Some examples would be of great help.

Michel Ayres
  • 5,891
  • 10
  • 63
  • 97

1 Answers1

9

If you look at the jQuery code you can see that all click() does is execute trigger('click'):

jQuery.each( ("blur focus focusin focusout load resize scroll unload click dblclick " +
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
"change select submit keydown keypress keyup error contextmenu").split(" "), function( i, name ) {

// Handle event binding
jQuery.fn[ name ] = function( data, fn ) {
    if ( fn == null ) {
        fn = data;
        data = null;
    }

    return arguments.length > 0 ?
        this.on( name, null, data, fn ) :
        this.trigger( name );
};

Note this:

    return arguments.length > 0 ?
        this.on( name, null, data, fn ) :
        this.trigger( name );

In other words, "If no arguments are passed to click, execute trigger('click')".

Armatus
  • 2,206
  • 17
  • 28
  • 1
    Might be worth mentioning that this is Standard Operating Procedure in the jQuery source code, or in any decent application for that matter -- if you want the same result, call the same code. The difference in performance between one and the other will always be negligible. – Blazemonger Apr 19 '12 at 14:18