jQuery class vs tag qualfied class selector (v6)

Revision 6 of this benchmark created by GaryJ on


Description

Just came across this article http://www.artzstudio.com/2009/04/jquery-performance-rules/ that recommends both tag qualifying class selectors as well as descending from an id for maximum jquery performance. Thought I'd test it out on his examples, because I've learned that you never want to tag qualify ids OR classes if you don't have to (similarly to CSS). However, considering the age of the article, the way jquery works could well be different now.

Preparation HTML

<div id="content"> 
   <div class="on">
   </div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
class selector
$('.on')
ready
tag qualified class selector
$('div.on')
ready
#id descendant class selector
$('#content .on')
ready
#id descendant tag qualified class selector
$('#content div.on')
ready
find
$('#content').find('.on')
ready
children
$('#content').children('.on')
ready
child selector
$('#content > .on')
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.