Fastest Way To Append A Dynamic JavaScript Class
JavaScript performance comparison
Info
https://twitter.com/toddmotto/status/307237792600162304
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="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</body>
</html>
Preparation code output
some random text
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Pure JavaScript |
|
pending… |
jQuery toggleClass() |
|
pending… |
jQuery .removeClass().addClass() |
|
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:
- Revision 1: published by Donovan Glover
- Revision 2: published
- Revision 4: published by Mike McCaughan
- Revision 5: published
0 comments