hasClass vs is with multiple classes

JavaScript performance comparison

Revision 13 of this test case created by Bob Radu

Preparation code

<div id="foo" class"classOne">I am a DIV</div>
<div id="foo1" class"classTwo">I am a DIV</div>
<div id="foo2">I am a DIV</div>
<div id="foo3">I am a DIV</div>
<div id="foo4">I am a DIV</div>
<div id="foo5">I am a DIV</div>
<div id="foo6" class"classOne">I am a DIV</div>
<div id="foo7">I am a DIV</div>
<div id="foo8" class"classTwo">I am a DIV</div>
<div id="foo9">I am a DIV</div>
<div id="foo10">I am a DIV</div>
<div id="foo11">I am a DIV</div>
<div id="foo12">I am a DIV</div>
<div id="foo13" class"classOne">I am a DIV</div>
<div id="foo14">I am a DIV</div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

Preparation code output

I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV
I am a DIV

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
hasClass
$('#foo').hasClass('classOne') || $('#foo').hasClass('classTwo');
pending…
is
$('#foo').is('.classOne, .classTwo');
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