jQuery event delegation

JavaScript performance comparison

Revision 36 of this test case created by Aaron Forsander

Preparation code

<div id="parent"></div>
<div id="parent2"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
Benchmark.prototype.setup = function() {
    $('#parent2').on('click', '.clickable', function() {

Benchmark.prototype.teardown = function() {

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
no delegation
var $target = $("<div class='clickable'></div>").appendTo('#parent');
$target.on('click', function() {
with delegation
var $target = $("<div class='clickable'></div>").appendTo('#parent2');

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment