jQuery .find() vs. context selector

JavaScript performance comparison

Revision 5 of this test case created by jhongomz

Info

comparing selector speed

Preparation code

<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>
 

Preparation code output

A test

This is text

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Find class
var hasFrame = $('#someId').find('.someClass').length > 0 ? true : false;
pending…
class selector
var hasFrame = $('.someClass').length > 0 ? true : false;
pending…
context selector (id)
var hasFrame = $('#someId .someClass').length > 0 ? true : false;
pending…
context selector (tag)
var hasFrame = $('p.someClass').length > 0 ? true : false;
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. Here’s a list of current revisions for this page:

0 comments

Add a comment