index or n-th child jquery

Benchmark created by Greg on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="select">
  <span class="child">
    Foo
  </span>
  <span class="child">
    Foo
  </span>
  <span class="child">
    Foo
  </span>
  <span class="child">
    Foo
  </span>
  <span class="child">
    Foo
  </span>
  <span class="child">
    Foo
  </span>
  <span class="child">
    Foo
  </span>
  <span class="child">
    Foo
  </span>
  <span class="child">
    Foo
  </span>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
by index
var select = $('#select');
var fourthChild = select.children()[3];
ready
by nth
var select = $('#select');
var byNth = $('*:nth-child(' + 3 + ')', select)
ready

Revisions

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