jquery addClass and hasClass vs add attribute and css
JavaScript performance comparison
Info
This test case is checking the class of div. If it exists, remove it and add a seperate style.
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="test" class="open" opened="true">Test</div>
<style>
open{color:green;}
closed{color:red;}
</style>
<script>
Benchmark.prototype.setup = function() {
var $test = $("#test");
};
</script>
Preparation code output
Test
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
addClass |
|
pending… |
attr and inline style |
|
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 Mohit Seth
0 comments