bind-vs-on

JavaScript performance comparison

Revision 17 of this test case created by AntonyRaj

Info

Comparison of jQuery bind() and on() methods when binding to the same event on multiple elements.

Preparation code

<script src="http://code.jquery.com/jquery-1.7.2.min.js">
</script>
<ul>
  <li>one</li>
  <li>two</li>
  <li>three</li>
  <li>four</li>
  <li>five</li>
  <li>six</li>
  <li>seven</li>
  <li>eight</li>
  <li>nine</li>
  <li>ten</li>
</ul>
<script>
Benchmark.prototype.setup = function() {
    var update = function(e) {
        $(this).html('foo');
        }
};
</script>

Preparation code output

  • one
  • two
  • three
  • four
  • five
  • six
  • seven
  • eight
  • nine
  • ten

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
bind()
$('ul li').live('click', update);
pending…
on
$('ul').on('click', 'li', update);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment