Bind vs. Click

Benchmark created by Trevor Davis on


Description

Determining whether it is faster to do click() or bind('click')

Preparation HTML

<ul id="nav">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Blog</a></li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
Bind
$(document).ready(function() {
 $('#nav').find('a').bind('click', function(e) {
  alert($(this).text());
  e.preventDefault();
 });
});
ready
Click
$(document).ready(function() {
 $('#nav').find('a').click(function(e) {
  alert($(this).text());
  e.preventDefault();
 });
});
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.