0

I've read the posts of live() versus delegate() versus on(), and understand the position.

I also understand how click() is just a shortcut for on(), and how the two statements are identical.

$( "#clickTarget" ).click(function() {alert( "Handler for .click() called." );});
$( "#onTarget" ).on('click',function() {alert( "Handler for .on() called." );});

My question is whether there is any advantage of using bind() over on()? Note that the documentation states "As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document." For instance, if my element exists upon writing of the DOM, it seems to make sense. If so, is there a shortcut version of bind() which binds on click?

$( "#bindTarget" ).bind( "click", function() {alert( "Handler for .bind() called" );});
user1032531
  • 24,767
  • 68
  • 217
  • 387
  • "As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document. For earlier versions, the .bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to .bind() occurs. For more flexible event binding, see the discussion of event delegation in .on() or .delegate()." - jQuery documentation – opznhaarlems Oct 07 '13 at 13:26

1 Answers1

7

From jQuery source code :

bind: function( types, data, fn ) {
    return this.on( types, null, data, fn );
},

As you see, bind just calls on. There's NO reason to use bind. Never.

Eugene Naydenov
  • 7,165
  • 2
  • 25
  • 43
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758