Bind vs Delegate jQuery

Benchmark created by Steven on


Preparation HTML

<div id="stepr">
  <div class="ui-step" id="step1">
  </div>
  <div class="ui-step">
  </div>
  <div class="ui-step">
  </div>
  <div class="ui-step">
  </div>
  <div class="ui-step">
  </div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Setup

var $stepr = $('#stepr'),
        $steps = $stepr.find('.ui-step');

Test runner

Ready to run.

Testing in
TestOps/sec
Bind
$steps.bind('click', function() {
  $(this).addClass('clicked');
});
ready
Delegate
$stepr.delegate("div.ui-step", "click", function() {
  $(this).addClass('clicked');
});
ready
Bind Specific
$('#step1').bind('click', function() {
  $(this).addClass('active');
});
ready
Delegate Specific
$stepr.delegate("#step1", "click", function() {
  $(this).addClass('active');
});
ready

Revisions

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

  • Revision 1: published by Steven on