jQuery .live() vs .delegate() vs .on()

JavaScript performance comparison

Revision 30 of this test case created by tyareg

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js">
</script>
<div id="context">
  <p>
    Some paragraph
  </p>
  <p id="element">
    Some ID'd paragraph
  </p>
</div>

Preparation code output

Some paragraph

Some ID'd paragraph

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()
$('p').live('click', $.noop);
pending…
.live() with context
$('p', $('#context')).live('click', $.noop);
pending…
.delegate()
$('#context').delegate('p', 'click', $.noop);
pending…
.delegate() on document
$(document).delegate('p', 'click', $.noop);
pending…
.on()
$('#context').on('click', 'p', $.noop);
pending…
.on() on document
$(document).on('click', 'p', $.noop);
pending…
.delegate() on context using ID
$('#context').delegate('#element', 'click', $.noop);
pending…
.delegate() on document using ID
$(document).delegate('#element', 'click', $.noop);
pending…
.on() on context using ID
$('#context').on('click', '#element', $.noop);
pending…
.on() on document using ID
$(document).on('click', '#element', $.noop);
pending…
click()
$('#element').on('click', $.noop);
pending…
click
$('#element').click($.noop);
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