getComputedStyle vs style vs .css()

JavaScript performance comparison

Revision 10 of this test case created by David

Info

getComputedStyle vs style vs .css()

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="element" style="width:200px">
  My Element
</div>

Preparation code output

My Element

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jq css {width}
var element = $("#element"),
    width = parseInt(element.css("width"));
pending…
js .width()
var element = $("#element"),
    width = element.width()
pending…
style
var element = document.getElementById("element"),
    width = parseInt(element.style.width);
pending…
getComputedStyle
var element = document.getElementById("element"),
    width = parseInt(getComputedStyle(element).width);
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:

0 comments

Add a comment