1

I know that .click(function()) doesn't work on dynamic objects, but .on('click', function()) does, given the circumstance.

Is there any downside to using .on('click') all of the time?

I've become accustom to using .on to handle all of my events, regardless of whether it's dynamic or not.

1
  • 3
    This is not event delegation. These are just 2 different ways of binding events.
    – lshettyl
    Commented Mar 25, 2014 at 16:31

1 Answer 1

2

These are just two different ways of adding an event handler,

See here: http://jsperf.com/jquery-on-versus-click/2

They are almost identical, but .on('click', function() seems to be faster by the smallest amount.

.click(function()

143,775
±5.23%
fastest

vs

.on('click', function()

148,059
±5.66%
fastest
1
  • 3
    You're reading the results incorrectly, .on('click', function() {}) is the faster of the two. That makes sense, considering .click() calls .on('click') internally, as far as I recall. Commented Mar 25, 2014 at 16:42

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