Jquery Selectors (v2)

Revision 2 of this benchmark created on


Description

different ways of handling jquery

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div class="foo">
        foo
        <div class="foo">
                foo
                <div class="foo">
                        foo
                        <div class="foo">
                                foo
                                <div class="foo">
                                        foo
                                        <div class="foo">
                                                foo
                                                <div class="foo">
                                                        foo
                                                        <div class="foo">
                                                                foo
                                                                <div class="bar">
                                                                        bar
                                                                        <div class="biz">
                                                                                biz
                                                                        </div>
                                                                </div>
                                                        </div>
                                                </div>
                                        </div>
                                </div>
                        </div>
                </div>
        </div>
</div>

Setup

var bar = $('.bar');
    var __EXPECTED__ = $('.biz');
    function assert(condition, message) {
        if (!condition) {
            throw message || "Assertion failed";
        }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
direct
var bizs = $('.biz');
assert( bizs.length == __EXPECTED__.length );
ready
direct+within
var bizs = $('.biz', bar);
assert( bizs.length == __EXPECTED__.length );
ready
find
var bizs = bar.find('.biz');
assert( bizs.length == __EXPECTED__.length );
 
ready
has
var bizs = bar.has('.biz');
assert( bizs.length == __EXPECTED__.length );
ready

Revisions

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