Jquery .css() vs JS.style

JavaScript performance comparison

Revision 12 of this test case created by totty90

Info

Show and hide element

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="testj1" style="position:absolute;top:100px;left:200px;"></div>
<div id="testj2" style="position:absolute;top:100px;left:200px;"></div>
<div id="testj3" style="position:absolute;top:100px;left:200px;"></div>
<div id="test1" style="position:absolute;top:100px;left:200px;"></div>
<div id="test2" style="position:absolute;top:100px;left:200px;"></div>
<div id="test3" style="position:absolute;top:100px;left:200px;"></div>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
jQuery 1
jQuery("#testj1").hide().show();
pending…
jQuery 2
jQuery("#testj2").css('display', 'none').css('display', 'block');
pending…
jQuery 3
jQuery("#testj3").toggle().toggle();
pending…
Javascript
var myelem1 = document.getElementById("test1");
myelem1.style.display = "none";
myelem1.style.display = "block";
pending…
Javascript cssText
var myelem2 = document.getElementById("test2");
myelem2.style.cssText = "display:none;display:block";
pending…
Javascript setStyle attribute
var myelem3 = document.getElementById("test3");
myelem3.setAttribute('style', "display:none;display:block");
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