1

I have several event handlers that I bind like this:

$('#MyDiv').click(function () {...});
$('#SomeDiv').mouseenter(function () {...});

These handlers are bound in the document.ready function and don't need to be rebound later because the HTML always stays the same. Will there be any performance gains by switching to the .bind() function or the newer .on() found in version 1.7.

Thanks for your suggestion.

frenchie
  • 51,731
  • 109
  • 304
  • 510

3 Answers3

3

Here is a test using jsperf: http://jsperf.com/jquery-click-vs-bind-vs-on. Turns out that on is the fastest.

EDIT: Just realized that I had an error in the setup. They have the same performance, sorry. http://jsperf.com/jquery-click-vs-bind-vs-on/2

Will
  • 19,661
  • 7
  • 47
  • 48
1

No. These are just shortcuts for calling bind/on.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
0

http://blog.jquery.com/2011/11/03/jquery-1-7-released/ scroll down to the graph of event performance jquery 1.7 alone improves performance so i would recommend .on with 1.7

Adam Merrifield
  • 10,307
  • 4
  • 41
  • 58