jQuery parent/child selectors (v15)

Revision 15 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 id="abc">
<table><td></td></table>
    </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 = $('table', $list);
ready
selector
var $test = $('#abc table');
ready
context and find()
var $test = $(list).find('table');
ready
created context
var $test = $('table', $('#list'));
ready
selector and find
var $test = $('#list').find('table');
ready
parent/child selector
var $test = $('#list > #abc > table');
ready
immediate children
$test = $(list).children().children('table');
ready
id
var $test = $('table');
ready
$list find
var $test = $list.find('table');
ready
plain context
var $test = $('table', list);
ready

Revisions

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