jQuery parent/child selectors (jQuery 2.1.0) (v72)

Revision 72 of this benchmark created by Christiaan Rakowski on


Description

The different ways to select (context, pure selector, +find()) DOM elements using jQuery in parent/child scenarios.

Preparation HTML

<script src="https://code.jquery.com/jquery-2.1.0.min.js">
</script>
<div>
  <ul class="list">
    <li class="test">
    </li>
    <li>
    </li>
    <li class="test">
    </li>
    <li class="test">
    </li>
    <li>
    </li>
    <li class="test">
    </li>
    <li>
    </li>
    <li class="test">
    </li>
    <li>
    </li>
    <li class="test">
    </li>
  </ul>
</div>
<div class="test">
</div>
<script>
  var list = document.getElementById('list');
var $list = $(list);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
context
var $test = $('.test', list);
ready
selector
var $test = $('.list .test');
ready
context and find()
var $test = $(list).find('.test');
ready
created context
var $test = $('.test', $('.list'));
ready
selector and find
var $test = $('.list').find('.test');
ready
parent/child selector
var $test = $('.list > .test');
ready
immediate children
$test = $(list).children('.test');
ready
jquery context
var $test = $('.test', $list);
ready
jquery context and find()
var $test = $list.find('.test');
ready
jquery immediate children
var $test = $list.children('.test');
ready
jquery context and find( > )
var $test = $list.find('> .test');
ready

Revisions

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