Jquery .css() vs JS.style

JavaScript performance comparison

Revision 8 of this test case created by Nicholas A

Info

Changes the background of div#test to black. Note: Uses the latest jQuery 1.6.

Preparation code

<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.min.js"></script>
<div id="test" style="height:100px;width:100px;position:absolute;top:-100px;left:-200px;"></div>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery
$("#test").css('backgroundColor', '#000');
pending…
JS
var myelem = document.getElementById("test");
myelem.style.backgroundColor = "#000";
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:

1 comment

Nicholas A (revision owner) commented :

I don't understand what's wrong with my test. I keep getting a some error about "$" (jQuery) not being defined.

Add a comment