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

Revision 19 of this benchmark created by Phillip Gourley on


Preparation HTML

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

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Setup

var el = document.getElementById("box");
  var $el = $(el);

Teardown



            el = null;
  $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
var tStyle = el.style;
tStyle.background = "#FF0000";
tStyle.width = "100px";
tStyle.height = "100px";
tStyle.display = "block";
tStyle.boxShadow = "1px 1px 5px 5px red";
ready
Native DOM (array)
var tStyle = el.style;
tStyle['background'] = "#FF0000";
tStyle['width'] = "100px";
tStyle['height'] = "100px";
tStyle['display'] = "block";
tStyle['box-shadow'] = "1px 1px 5px 5px red";
ready
Decoupling CSS from JS (jQuery)
$el.addClass('newstyle');
ready

Revisions

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