cached jquery selector

JavaScript performance comparison

Test case created by Lars

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<div class="myElement">
 <span></span>
 <span></span>
 <span></span>
 <span></span>
 <span></span>
 <span></span>
</div>
    

Preparation code output

<div class="myElement"> <span></span> <span></span> <span></span> <span></span> <span></span> <span></span> </div>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
without-variable
$myElement = $('.myElement span');
$myElement.each(function() {
  $(this).css('color', 'green');
});
pending…
with-variable
$myElement = $('.myElement span');
$myElement.each(function() {
  $myElement.find(this).css('color', 'green');
});
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.

0 Comments