jQuery: $().click(fn) vs. $().bind(‘click’,fn);

For what it’s worth, from the jQuery source:

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

    // Handle event binding
    jQuery.fn[name] = function(fn){
        return fn ? this.bind(name, fn) : this.trigger(name);
    };
});

So no, there’s no difference –

$().click(fn)

calls

$().bind('click',fn)

Leave a Comment