Event Delegation

JavaScript performance comparison

Test case created

Preparation code

<div>
  <p id="p1">f</p>
  <p id="p2">o</p>
  <p id="p3">o</p>
  <p id="p4">b</p>
  <p id="p5">a</p>
  <p id="p6">r</p>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Preparation code output

f

o

o

b

a

r

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Event Delegation
$('div').click(function(event) {
  if (event.target.id === 'p1') {
    // we have p1
  }
});

$('p:first').click();
pending…
Event on each p element
$('p').click(function(event) {
  if (event.target.id === 'p1') {
    // we have p1
  }
});

$('p:first').click();
pending…

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

Compare results of other browsers

0 comments

Add a comment