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

Revision 7 of this benchmark created 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>node ' + i + '</div>');
  }
  $(document.body).append(nodes.join(''));
</script>

Test runner

Ready to run.

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

Revisions

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