jQuery .find() vs. context selector (v5)

Revision 5 of this benchmark created by jhongomz on


Description

comparing selector speed

Preparation HTML

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

<div id="someId">
<p>A test</p>
<p>
     <p class="someClass"></p>
</p>
<p>This is text</p>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
Find class
var hasFrame = $('#someId').find('.someClass').length > 0 ? true : false;
ready
class selector
var hasFrame = $('.someClass').length > 0 ? true : false;
ready
context selector (id)
var hasFrame = $('#someId .someClass').length > 0 ? true : false;
ready
context selector (tag)
var hasFrame = $('p.someClass').length > 0 ? true : false;
ready

Revisions

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