jquery selector speed

JavaScript performance comparison

Revision 60 of this test case created

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.7.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');
pending…
2. by class
$('.container5').css('border','1px solid red');
pending…
3. by element and id
$('div#container5').css('border','1px solid red');
pending…
4. by element and class
$('div.container5').css('border','1px solid red');
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:

1 comment

John Marty commented :

Please add $("div").find("#container5").css('border','1px solid red'); for comparison.

Add a comment