jquery last-child css selector vs last method

Benchmark created by Dan Heberden on


Description

Testing $(document.body).children(':last-child') vs $(document.body).children().last();

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
$(document.body).children(':last-child');
ready
.last()
$(document.body).children().last();
ready

Revisions

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