jQuery document on vs ready (v5)

Revision 5 of this benchmark created on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<table data-foo="True">
<tr>
  <th>Hello</th><td>World</td>
</tr>
</table>

Setup

function makeYellow() {
       $('[data-foo]').find('td').css('background','yellow');
    }
    
    function makeYellow2($selector) {
       $selector.find('td').css('background','yellow');
    }

Test runner

Ready to run.

Testing in
TestOps/sec
on()
$(document).on('ready',makeYellow());
ready
ready
$(document).ready(makeYellow());
ready
on(), object in context
$(document).on('ready','[data-foo]', makeYellow());
ready
on.ready passing selector
$(document).on('ready','[data-foo]',function() {
    $(this).find('td').css('background','yellow');
});
ready
on ready passing selector to function
$(document).on('ready','[data-foo]',function() {
    makeYellow2($(this));
});
ready

Revisions

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