hasClass vs is so

JavaScript performance comparison

Revision 14 of this test case created

Info

To confirm a question asked here:

http://stackoverflow.com/questions/4901553/jquery-hasclass-vs-is

I belive hasClass should be faster.

Preparation code

<div id="foo">I am a DIV</div>

(jQuery 2.1.1 - lastest)

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Preparation code output

I am a DIV
(jQuery 2.1.1 - lastest)

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('bar');
pending…
is
$('#foo').is('.bar');
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