jQ id only vs with child

JavaScript performance comparison

Test case created by

Preparation code

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

<div class="container">
<div id="some-id">
    <div class="title">
        Table of Contents (p. i)
    </div>
    <div class="src">
        Stuff and Things
    </div>
<ul class="mln format inline-list">
    <li class="mln">
        <a href="#" class="bold">
            Read  Online
        </a>
    </li>
    <li>
        <a class="bold" href="#" target="_blank">
            Download
        </a>
    </li>
    <li class="childElement">
        <a href="#" class="bold">Add to Cart</a>
    </li>
  </ul>
</div>
</div>
      
<script>
Benchmark.prototype.teardown = function() {
  $("#test").remove();

};
</script>

Preparation code output

<div class="container"> <div id="some-id"> <div class="title"> Table of Contents (p. i) </div> <div class="src"> Stuff and Things </div> <ul class="mln format inline-list"> <li class="mln"> <a href="#" class="bold"> Read Online </a> </li> <li> <a class="bold" href="#" target="_blank"> Download </a> </li> <li class="childElement"> <a href="#" class="bold">Add to Cart</a> </li> </ul> </div> </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
with find
var myStuff = $("#some-id").find(".childElement");

$(".container").append("<div id='test'>"+ myStuff +"</div>");
pending…
single selector
var myStuff = $("#some-id .childElement");

$(".container").append("<div id='test'>"+ myStuff +"</div>");
pending…

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

0 Comments

Table of Contents (p. i)
Stuff and Things