jQuery chaining (v18)

Revision 18 of this benchmark created on


Description

Tests whether chaining jQuery function calls is noticeably faster than separate calls.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="theDiv">Some text</div>

Test runner

Ready to run.

Testing in
TestOps/sec
Chained
$('document')
.on('click','#theDiv',function() { $(this).addClass('test') })
.on('click','#theDiv',function() { $(this).removeClass('test') })
;
ready
Separate calls
$('document').on('click','#theDiv',function() { $(this).addClass('test') });
$('document').on('click','#theDiv',function() { $(this).removeClass('test') });
ready
Separate calls (cached)
var d = $('document');
d.on('click','#theDiv',function() { $(this).addClass('test') });
d.on('click','#theDiv',function() { $(this).removeClass('test') });
ready
Cached + chained
var d = $('document');
d.on('click','#theDiv',function() { $(this).addClass('test') }).on('click','#theDiv',function() { $(this).removeClass('test') });
ready

Revisions

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