Browser Diet - jQuery Selectors

JavaScript performance comparison

Revision 30 of this test case created

Preparation code

<div>
  <ul id="list">
    <li class="test"></li>
    <li>
      <ul id="list2">
    <li class="test"></li>
    <li></li>
    <li class="test"></li>
    <li></li>
    <li class="test"></li>
    <li id="findMe" class="findMe"></li>
    <li class="test"></li>
    <li></li>
    <li class="test"></li>
  </ul>
    </li>
    <li class="test"></li>
    <li></li>
    <li class="test"></li>
    <li></li>
    <li class="test"></li>
    <li></li>
    <li class="test"></li>
  </ul>
</div>

<div class="test"></div>

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

<script>
  var list = document.querySelector('#list');
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
context
var $test = $('.findMe', list);
pending…
selector
var $test = $('#list .findMe');
pending…
context and find()
var $test = $(list).find('.findMe');
pending…
created context
var $test = $('.findMe', $('#list'));
pending…
selector and find
var $test = $('#list').find('.findMe');
pending…
parent/child selector
var $test = $('#list > .findMe');
pending…
immediate children
$test = $(list).children('.findMe');
pending…
Native
$test = $(document.querySelectorAll('#list > .findMe'))
pending…
Native + context
$test = $(list.querySelectorAll('.findMe'))
pending…
Native
$test = document.querySelector('#findMe');
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