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

Revision 45 of this benchmark created on


Preparation HTML

<div id="box">I'm a box</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");
  el.className = "";
  el.setAttribute("style", "");

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

Revisions

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