Jacob Raccuia
Jacob Raccuia

Reputation: 1686

Using on('click') when I could also use .click()

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.

Upvotes: 1

Views: 60

Answers (1)

JF it
JF it

Reputation: 2403

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

Upvotes: 2

Related Questions