live-vs-on

JavaScript performance comparison

Revision 22 of this test case created by Sunny

Info

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

Preparation code

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.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
live()
$('li').live('click', update);
pending…
on
$(document).on('click', 'li', update);
pending…
bind()
$('li').bind('click', 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