I m confused in Jquery bind, live, unbind, delegate, on method

I am learning Jquery, and I am totally confused in bind, live, delegate, on, unbind method,
can any 1 tell me exact difference in these methods…

Regards

Bind lets you attach an event handler on to an element.

$( "#foo" ).bind( "click", function() {
  alert( "User clicked on 'foo.'" );
});

A preferred way to do this is to use the on method.

$( "#foo" ).on("click", function() {
  alert( "User clicked on 'foo.'" );
});

Live lets you attach event handlers on to elements that don’t yet exist. It watches and waits for jQuery to add those elements, and when they’re added the event handlers are then attached to them.

$( "a.offsite" ).live( "click", function() {
  alert( "Goodbye!" ); // jQuery 1.3+
});

Using live is no longer recommended, and is instead done now using the on method by attaching the event handler to the document, and using a query selector to specify what we’re watching for…

$( document ).on( "click", "a.offsite", function() {
  alert( "Goodbye!" );
});

Delegate provided a way to attach an event handler on to multiple elements within a container.

$( "table" ).delegate( "td", "click", function() {
  $( this ).toggleClass( "chosen" );
});

It has since been replaced by the on method.

$( "table" ).on( "click", "td", function() {
  $( this ).toggleClass( "chosen" );
});

Basically the on method has replaced all of the other bind/live/delegate techniques.

Unbind is to remove an event handler.

$( "#foo").unbind( "click" );

Did you mean that to say .on Paul :smile:

Err, yes indeed. Fixed.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.