jQuery .css() vs. MooTools .setStyles() vs. DOM .style

JavaScript performance comparison

Test case created by Yu-Cheng Chuang

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/mootools/1.3/mootools-yui-compressed.js"></script>
<div id="test">Hello! World</div>

      
<script>
Benchmark.prototype.setup = function() {
  var element = document.getElementById("test");
  var $element = $(element); // avoid overhead on jQuery object wrapping
  

};

Benchmark.prototype.teardown = function() {
  document.getElementById("test").removeAttribute("style");

};
</script>

Preparation code output

<div id="test">Hello! World</div>

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
jQuery .css()
$element.css({
  "height": "320px", // eliminate `+= "px"' overhead
  "width": "240px",
  "color": "orange",
  "background-color": "black"
});
pending…
element.style
element.style.height = "320px";
element.style.width = "240px";
element.style.color = "orange";
element.style.backgroundColor = "black";
pending…
element.style.cssText=
element.style.cssText = "height: 320px; width: 240px; color: orange; background-color: black;";
pending…
MooTools .setStyles()
element.setStyles({
  "height": "320px",
  "width": "240px",
  "color": "orange",
  "background-color": "black"
});
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

Hello! World