jQuery Selector Chaining
JavaScript performance comparison
Preparation code
<div class="container">
<div class="main">
<ul class="list-1">
</ul>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
var i, html = "";
for(i = 0; i < 500; i++) {
html += "<li class=\"odd\">item</li> <li>item</li>"
}
$(".list-1").html(html);
};
</script>
Preparation code output
<div class="container">
<div class="main">
<ul class="list-1">
</ul>
</div>
</div>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
One selector
|
|
pending… |
Chained with find
|
|
pending… |
Chained with children
|
|
pending… |
Chained with children selecting '.odd'
|
|
pending… |
One selector finding '.odd'
|
|
pending… |
Cut to the chase
|
|
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