Attribute vs Class selection

JavaScript performance comparison

Revision 14 of this test case created

Info

Tests speed of selection for data attribute selection versus class-based selection.

Preparation code

<ul>
<li id="1" data-cargroup="A" class="js-CarGroup-A">A</li>
<li id="2" data-cargroup="B" class="js-CarGroup-B">B</li>
<li id="3" data-cargroup="C" class="js-CarGroup-C">C</li>
<li id="4" data-test="test" class="css-test">C</li>
<li id="5" data-cargroup="D" class="js-CarGroup-D">D</li>
<li id="6" data-test="test" class="css-test">E</li>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Preparation code output

  • A
  • B
  • C
  • C
  • D
  • E

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Data-attribute selection
$('[data-test]');
pending…
Class-based selection
$('.css-test');
pending…
new
$('[data-test]','ul');
pending…
new2
$('.css-test','ul');
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. Here’s a list of current revisions for this page:

0 comments

Add a comment