Fastest Way To Append A Dynamic JavaScript Class

JavaScript performance comparison

Test case created by Donovan Glover

Preparation code

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Test Page</title>
 </head>
 <body>
  <div class="wrapper">
   <p>some random text</p>
  </div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 </body>
</html>

    

Preparation code output

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Test Page</title> </head> <body> <div class="wrapper"> <p>some random text</p> </div> </body> </html>

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
Pure JavaScript
document.body.className = document.body.className.replace("no-js","js");
pending…
jQuery toggleClass()
$("body").toggleClass("no-js js");
pending…
jQuery .removeClass().addClass()
$("body").removeClass("no-js").addClass("js");
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

Test Page

some random text