jQuery class vs tag qualfied class selector

JavaScript performance comparison

Revision 47 of this test case created by

Preparation code

<div id="content">
  <form method="post" action="/">
    <h2>Traffic Light</h2>
    <ul id="traffic_light">
      <li><input type="radio" class="on" name="light" value="red" /> Red</li>
      <li><input type="radio" class="off" name="light" value="yellow" /> Yellow</li>
      <li><input type="radio" class="off" name="light" value="green" /> Green</li>
    </ul>
    <input class="button" id="traffic_button" type="submit" value="Go" />
  </form>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    

Preparation code output

<div id="content"> <form method="post" action="/"> <h2>Traffic Light</h2> <ul id="traffic_light"> <li><input type="radio" class="on" name="light" value="red" /> Red</li> <li><input type="radio" class="off" name="light" value="yellow" /> Yellow</li> <li><input type="radio" class="off" name="light" value="green" /> Green</li> </ul> <input class="button" id="traffic_button" type="submit" value="Go" /> </form> </div>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
class selector
$('.on')
pending…
tag qualified class selector
$('input.on')
pending…
#id descendant class selector
$('#traffic_light .on')
pending…
#id descendant tag qualified class selector
$('.on #traffic_light')
pending…
find
$('#traffic_light').find('.on')
pending…

Compare results of other browsers

Revisions

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

0 Comments

Traffic Light