jQuery parent/child selectors (v70)

Revision 70 of this benchmark created on


Description

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

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div>
  <ul id="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>
</div>
</div>
<script>
  var list = document.getElementById('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
child
$test = $('.test').children(':first-child');
ready
Test
$test = $('.test:first-child');
ready
test 2
$test = $('.test').children('div:first-child');
ready

Revisions

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