.delegate() vs .on()

The .on() syntax is the new syntax that version 1.7 uses and it is meant to substitute .bind(), .delegate() and .live().

More here -> http://blog.jquery.com/2011/11/03/jquery-1-7-released/

New Event APIs: .on() and .off()

The new .on() and .off() APIs unify all the ways of attaching events
to a document in jQuery — and they’re shorter to type!

  $(elements).on( events [, selector] [, data] , handler );
  $(elements).off( [ events ] [, selector] [, handler] );

When a selector is provided, .on() is similar to .delegate() in that
it attaches a delegated event handler, filtered by the selector. When
the selector is omitted or null the call is like .bind(). There is one
ambiguous case: If the data argument is a string, you must provide
either a selector string or null so that the data isn’t mistaken as a
selector. Pass an object for data and you’ll never have to worry about
special cases.

All the existing event binding methods (and their corresponding
unbinding methods) are still there in 1.7, but we recommend that you
use .on() for any new jQuery project where you know version 1.7 or
higher is in use.
(emphasis mine)

Leave a Comment