Stackoverflow question jQuery selectors

Benchmark created by Andreas Göbel on


Preparation HTML

<span class="a">Test</span>
<div class="b">
  <div id="x_ABC">ABC must NOT be hidden</div>
  <div id="x_DEF">DEF must be hidden</div>
  <div id="x_GHI">GHI must be hidden</div>
  <div id="JKL">JKL must NOT be hidden</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Test runner

Ready to run.

Testing in
TestOps/sec
pure sizzle
$('.a + div.b div[id^="x"]:gt(0)').hide()
 
ready
sizzle with slice
$('.a + div.b div[id^="x"]').slice(1).hide()
 
ready
functional
$('.b').each(function(_, b) {
    var $b = $(b);

    if( 1 ) {
        $b.find('div').slice(1).filter(function() { return this.id.charAt(0) === 'x' }).hide();
    }
});
 
ready

Revisions

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

  • Revision 1: published by Andreas Göbel on