jquery selector speed id vs class index

JavaScript performance comparison

Revision 114 of this test case created

Preparation code

<div id="container">
  <ul>
    <li id="byID">1</li>
    <li class="unique_class">2</li>
    <li class="multi_class">3</li>
    <li class="multi_class">4</li>
  </ul>
</div><script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 

Preparation code output

  • 1
  • 2
  • 3
  • 4

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
$('#target')
$('#byID').html('1');
pending…
$('.target') only 1 class on page
$('.unique_class').html('2');
pending…
$('.target').first()
$('.multi_class').first().html('3');
pending…
$('.target:eq(1)')
$('.multi_class:eq(1)').html('4');
pending…
$('.target', '#target').
$('.multi_class', '#container').first().html('5');
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