jQuery selector vs hasClass (v24)

Revision 24 of this benchmark created by kp on


Description

Test which is faster, a selector including the class compared to hasClass.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<html class="ios">
<body>
  <h1>Test</h1>
</body>
</html>

Test runner

Ready to run.

Testing in
TestOps/sec
selector
if ($("html.ios").length > 0) {
 return true;
}
ready
hasClass
if ($("html").hasClass("ios")) {
 return true;
}
ready

Revisions

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