Delegate VS On (v51)

Revision 51 of this benchmark created by CyberDenix on


Description

Determining whether it is faster to do Delegate or On

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
1
$('#nav').delegate('a', 'click', function(e) {
 e.preventDefault();
});
ready
2
$(document).delegate('a', 'click', function(e) {
 e.preventDefault();
});
ready
3
$('#nav').on('a', 'click', function(e) {
 e.preventDefault();
});
ready
4
$(document).on('a', 'click', function(e) {
 e.preventDefault();
});
ready

Revisions

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