Re-wrapping jQuery objects

JavaScript performance comparison

Test case created by thefrontender

Info

Re-wrapping jQuery objects is unnecessary and slows down your code.

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<ul>
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
<li>Item four</li>
<li>Item five</li>
</ul>

Preparation code output

  • Item one
  • Item two
  • Item three
  • Item four
  • Item five

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Wrapped once
$('li').each(function(){
    var $li = $(this);
    if ($li.is(":contains('two')")) {
        $li.addClass('hilite');
    }
});
pending…
Wrapped multiple times
$('li').each(function(){
    var li = $(this);
    if ($(li).is(":contains('two')")) {
        $(li).addClass('hilite');
    }
});
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