jquery selector speed

JavaScript performance comparison

Revision 23 of this test case created by SkeLLLa

Preparation code

<div id="container0"></div>
<div class="container0 customclassA1 customclassB1"></div>
<div id="container1"></div>
<div class="container1 customclassA1 customclassB1"></div>
<div id="container2"></div>
<div class="container2 customclassA2 customclassB1"></div>
<div id="container3"></div>
<div class="container3 customclassA2 customclassB2"></div>
<div id="container4"></div>
<div class="container4 customclassA3 customclassB2"></div>
<div id="container5"></div>
<div class="container5 customclassA3 customclassB2"></div>
<div id="container6"></div>
<div class="container6 customclassA4 customclassB3"></div>
<div id="container7"></div>
<div class="container7 customclassA4 customclassB3"></div>
<div id="container8"></div>
<div class="container8 customclassA5 customclassB3"></div>
<div id="container9"></div>
<div class="container9 customclassA5 customclassB4"></div>
<div id="container10"></div>
<div class="container10 customclassA6 customclassB4"></div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></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
1. by id
$('#container5').css('border','1px solid red');
2. by class
$('.container5').css('border','1px solid red');
3. by element and id
$('div#container5').css('border','1px solid red');
4. by element and class
$('div.container5').css('border','1px solid red');

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment