jQuery eq vs nth-child (v4)

Revision 4 of this benchmark created by Michael Wright on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<ul id="test">
  <li>
    Item 1
  </li>
  <li>
    Item 2
  </li>
  <li>
    Item 3
  </li>
  <li>
    Item 4
  </li>
  <li>
    Item 5
  </li>
</ul>

Setup

var $test = $('#test');

Test runner

Ready to run.

Testing in
TestOps/sec
eq
$test.find(':eq(3)');
ready
nth-child
$test.find(':nth-child(2)');
ready
.eq()
$test.find('li').eq(3);
ready
[]
$($test.find('li')[3]);
ready
$()
$('li:eq(3)', $test);
ready
$().eq()
$('li', $test).eq(3)
ready
$('#test')
$('#test li:eq(3)')
ready
$('#test')
$('#test li').eq(3)
ready

Revisions

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