jquery last-child css selector vs last method (v3)

Revision 3 of this benchmark created by temp01 on


Description

Testing various ways to select last child element.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
  var nodes = [];
  for (i = 0; i < 10000; i++) {
   nodes.push('<div class="item' + i + '"><span>node ' + i + '</span></div>');
  }
  $(document.body).append(nodes.join(''));
  $(document.body).append('<div id="lastNode">One Node to rule them all, One Node to find them, One Node to bring them all and in the darkness bind them </div>');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
:last-child
$('body').children(':last-child');
ready
.last()
$('body').children().last();
ready
.slice(-1)
$('body').children().slice(-1)
ready
qSA child selector
$('body > *').last()
ready

Revisions

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