jQuery versus className
JavaScript performance comparison
Info
A quick test to see the performance based on using jQuery's .attr('class') versus the native className;
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<div class="wrapper">
<div class="innerWrapper">
<div id="getMe" class="button">
<a href="javascript:void(0)" id="button" class="buttonRef">
<span class="buttonText">Text</span>
</a>
</div>
</div>
</div>
<script>
var jElem = $("#getMe");
var dElem = document.getElementById("getMe");
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
1. jQuery - get Element + get Class |
|
pending… |
2. GET DOM ELEM + get Class |
|
pending… |
3. jQuery get Class |
|
pending… |
4. DOM get class |
|
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 JC Fant
0 comments