Different jQuery Selector Tests

Benchmark created by George Butiri on


Description

I want to find out what happens with different selectors comparing elements, classes and ids.

Preparation HTML

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

<div id="a" class="a">
    <p id="p" class="p"></p>
</div>

Setup

$('#a #p');
    $('#a p');
    $('#a .p');
    $('div #p');
    $('div p');
    $('div .p');
    $('.a #p');
    $('.a p');
    $('.a .p');
    
    $('#a').find('#p');
    $('#a').find('p');
    $('#a').find('.p');
    $('div').find('#p');
    $('div').find('p');
    $('div').find('.p');
    $('.a').find('#p');
    $('.a').find('p');
    $('.a').find('.p');

Test runner

Ready to run.

Testing in
TestOps/sec
$('#a #p');
$('#a #p');
 
ready
$('#a p');
$('#a p');
 
ready
$('#a .p');
$('#a .p');
 
ready
$('div #p');
$('div #p');
 
ready
$('div p');
$('div p');
 
ready
$('div .p');
$('div .p');
 
ready
$('.a #p');
$('.a #p');
 
ready
$('.a p');
$('.a p');
 
ready
$('.a .p');
$('.a .p');
ready
$('#a').find('#p');
$('#a').find('#p');

 
ready
$('#a').find('p');
$('#a').find('p');
 
ready
$('#a').find('.p');
$('#a').find('.p');
 
ready
$('div').find('#p');
$('div').find('#p');
 
ready
$('div').find('p');
$('div').find('p');
 
ready
$('div').find('.p');
$('div').find('.p');
 
ready
$('.a').find('#p');
$('.a').find('#p');
 
ready
$('.a').find('p');
$('.a').find('p');
 
ready
$('.a').find('.p');
$('.a').find('.p');
ready

Revisions

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

  • Revision 1: published by George Butiri on