jQuery selecters

Benchmark created by Dualta on


Description

A quick test to see what jQuery selectors are more efficient

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="header">
  <ul>
    <li>
      <a href="http://twitter.com">Twitter</a>
    </li>
    <li>
      <a href="http://www.facebook.com/">Facebook</a>
    </li>
    <li>
      <a id="google" class="google-link" href="http://www.google.com/">Google</a>
    </li>
    <li>
      <a href="http://www.youtube.com">Youtube</a>
    </li>
  </ul>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
id
$('#google');
ready
class
$('.google-link');
ready
attribute
$('a[href="http://www.google.com"]');
ready
nth child
$('ul li:nth-child(3) a');
ready
and the kitchen sink
$('div#header ul li a#google');
ready

Revisions

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