jQuery 1.7.1 (2) .click() vs .bind() vs .live() vs .delegate() vs .on()

JavaScript performance comparison

Revision 49 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"></script>
<script src="//www.cinsoft.net/mylib099-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<div id="all">
<div id="header">
<div id="logo">Logo</div>
<ul>
<li><a href="#">List 1</a></li>
<li><a href="#">List 2</a></li>
<li><a href="#">List 3</a></li>
<li><a href="#">List 4</a></li>
</ul>
</div>
<div id="contents">
<div id="main">
<h1>Some paragraph</h1>
<h2>Some paragraph</h2>
<p>Some paragraph</p>
<p>Some paragraph</p>
<ul>
<li><a href="#">List 1</a></li>
<li><a href="#">List 2</a></li>
<li><a href="#">List 3</a></li>
<li><a href="#">List 4</a></li>
</ul>
<h2>Some paragraph</h2>
<p>Some paragraph</p>
<h3>Some paragraph</h3>
<p>Some paragraph</p>
<p>Some paragraph</p>
</div>
<div id="navi">
<p>Some paragraph</p>
<ul>
<li><a href="#">List 1</a></li>
<li><a href="#">List 2</a></li>
<li><a href="#">List 3</a></li>
<li><a href="#">List 4</a></li>
</ul>
</div>
</div>
<div id="footer">
<ul>
<li><a href="#">List 1</a></li>
<li><a href="#">List 2</a></li>
<li><a href="#">List 3</a></li>
<li><a href="#">List 4</a></li>
</ul>
<p id="copyright">Copyright</p>
</div>
</div>

Preparation code output

Some paragraph

Some paragraph

Some paragraph

Some paragraph

Some paragraph

Some paragraph

Some paragraph

Some paragraph

Some 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()
// async test
$('#main p').live('click', $.noop);
pending…
.live() with main
// async test
$('p', $('#main')).live('click', $.noop);
pending…
.delegate()
$('#main').delegate('p', 'click', $.noop);
pending…
.delegate() on document
$(document).delegate('#main p', 'click', $.noop);
pending…
.on()
$('#main').on('click', 'p', $.noop);
pending…
.on() on document
$(document).on('click', '#main p', $.noop);
pending…
.bind()
$('#main p').bind('click', $.noop);
pending…
.click()
$('#main p').click($.noop);
pending…
.on() on p
$('#main p').on('click', $.noop);
pending…
.on() on body
$('body').on('click', '#main p', $.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