0

I gone through the different description provided for the .on() method or .delegate() method. But unable to clarify the actual need of .on() over .delegate().

I just came out with only one difference which of syntax nothing else.

.on() -- function( types, selector, data, fn ) .delegate -- function( selector, types, data, fn )

Any other difference?

1 Answer 1

3

Actually, delegate() uses on(), internally.

The jQuery delegate() method's source code:

function (selector, types, data, fn) {
    return this.on(types, selector, data, fn);
}

So no, other than calling one less function, there is no difference. delegate() is there purely to better differentiate between dynamically and statically added event listeners, should you want to.

4
  • delegate is kept for backward compatibility i guess
    – A. Wolff
    Commented Apr 4, 2014 at 15:38
  • 1
    From the .delegate() API docs: As of jQuery 1.7, .delegate() has been superseded by the .on() method.. So yeah, looks like backwards compatibility to me.
    – ajp15243
    Commented Apr 4, 2014 at 16:03
  • yup, it is. But which difference made them to deprecate the delegate and introduce the new .on method. they might have used the same. Commented Apr 5, 2014 at 5:44
  • Sorry, previously I thought superceeded means deprecated. Is there any major reason which made them to supeceeded the delegate and introduce the new .on method. Commented Apr 5, 2014 at 5:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.