jQuery event delegation (v33)

Revision 33 of this benchmark created on


Preparation HTML

<div id="parent"></div>
<div id="parent2"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Setup

$('#parent2').on('click', '.clickable', function() {
      $(this).toggleClass('active');
    });

Teardown


    $('.clickable').remove();
  

Test runner

Ready to run.

Testing in
TestOps/sec
no delegation
var $target = $("<div class='clickable'></div>").appendTo('#parent');
$('#parent').find($target).on('click', function() {
  $(this).toggleClass('active');
});
$target.click();
ready
with delegation
var $target = $("<div class='clickable'></div>").appendTo('#parent2');
$target.click();
ready

Revisions

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