jQuery.css() vs. native DOM (v60)

Revision 60 of this benchmark created on


Preparation HTML

<div id="box">I'm a box</div><div id="two">two</div><div id="three">three</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.0rc1/zepto.min.js">
</script>
<style>
.newClass{
  background: #FF0000;
  box-shadow: "1px 1px 5px 5px red";
  width: "100px";
  height: "100px";
  display: "block";
}
</style>

Setup

var el = document.getElementById("box");
  var el2 = document.getElementById("two");
  var el3 = document.getElementById("three");
  el.className = "";
  el.setAttribute("style", "");
  $el = $(el);
  $elSet = $("#box, #two, #three");

Teardown



            el = null;
        
  

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.css()
$el.css({
  background: "#FF0000",
  "box-shadow": "1px 1px 5px 5px red",
  width: "100px",
  height: "100px",
  display: "block"
});
ready
Native DOM
el.style.background = "#FF0000";
el.style.width = "100px";
el.style.height = "100px";
el.style.display = "block";
el.style.boxShadow = "1px 1px 5px 5px red";
ready
single CSS
$el.css('background', "#FF0000");
$el.css('box-shadow', "1px 1px 5px 5px red");
$el.css('width', "100px");
$el.css('height', "100px");
$el.css('display', "block");
ready
Native DOM ["style"]
el.style["background"] = "#FF0000";
el.style["width"] = "100px";
el.style["height"] = "100px";
el.style["display"] = "block";
el.style["box-shadow"] = "1px 1px 5px 5px red";
ready
add class
el.className += "newClass";
ready
style attr
el.setAttribute("style",
  "background: #FF0000;box-shadow: 1px 1px 5px 5px red;width: 100px;height: 100px;display: block;"
);
ready
cssText
el.style.cssText = "background: #FF0000;box-shadow: 1px 1px 5px 5px red;width: 100px;height: 100px;display: block;";
ready
$.css multiple
$elSet.css({
  background: "#FF0000",
  "box-shadow": "1px 1px 5px 5px red",
  width: "100px",
  height: "100px",
  display: "block"
});
ready
cssText multiple
el.style.cssText = el3.style.cssText = el2.style.cssText = "background: #FF0000;box-shadow: 1px 1px 5px 5px red;width: 100px;height: 100px;display: block;";
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.