jQuery nested $(".class") selectors (v10)

Revision 10 of this benchmark created by vol7ron on


Description

Testing whether selecting multiple class names is faster by various methods

Preparation HTML

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

<ul class="foo" id="bogi">
<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

<li class="bar">yay!<span class='sp'>test</span></li>

<li>yay!</li>

<li>yay!</li>

<li>yay!</li>

</ul>

Test runner

Ready to run.

Testing in
TestOps/sec
.find()
$(".foo").find(".bar")
ready
context
$(".bar",".foo")
ready
multiple classes in one $
$(".foo .bar")
ready
classes inside id
$("#bogi .bar")
ready
find classes inside id
$("#bogi").find(".bar")
ready
context with id
$(".bar", "#bogi")
ready
double find
$("#bogi").find(".bar").find(".sp")
ready
one more
$("#bogi").find(".bar .sp")
ready
my code
$("#bogi").find("li.bar")
ready
your code 1
$("#bogi").find("li").filter(".bar")
ready
your code 2
$("li").filter(".bar")
ready
your code 3
$(document.getElementsByTagName('li')).filter('.bar')
ready
your code 4
$('li', document.getElementById('bogi')).filter('.bar')
ready
your code 5
$(document.getElementsByTagName('li'),document.getElementById('bogi')).filter('.bar')
ready
your code 6
$(document.getElementById('bogi').getElementsByTagName('li')).filter('.bar')
ready

Revisions

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