jQuery document on vs ready

JavaScript performance comparison

Revision 5 of this test case created

Preparation code

<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>
<script>
Benchmark.prototype.setup = function() {
    function makeYellow() {
       $('[data-foo]').find('td').css('background','yellow');
    }
   
    function makeYellow2($selector) {
       $selector.find('td').css('background','yellow');
    }
};
</script>

Preparation code output

HelloWorld

Test runner

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

Java applet disabled.

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

Compare results of other browsers

Revisions

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:

0 comments

Add a comment