jQuery: css-display:none vs. hide

JavaScript performance comparison

Revision 6 of this test case created

Info

Testing on multiple elements

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div></div><div></div><div></div><div></div><div></div><div></div>
<div></div><div></div><div></div><div></div><div></div><div></div>
<div></div><div></div><div></div><div></div><div></div><div></div>
<div></div><div></div><div></div><div></div><div></div><div></div>
<div></div><div></div><div></div><div></div><div></div><div></div>
<div></div><div></div><div></div><div></div><div></div><div></div>
<div></div><div></div><div></div><div></div><div></div><div></div>
<script>
var cachedjQuery = $('div');
var cachedEl = document.getElementsByTagName("div");
</script>

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 :: display: none
$("div").css("display", "none");
pending…
jQuery :: hide()
$("div").hide();
 
pending…
jQuery :: display: none (cached)
cachedjQuery.css("display", "none");
 
pending…
jQuery :: hide() (cached)
cachedjQuery.hide();
pending…
Element (cached)
var i;
for(i = 0; cachedEl[i]; i++){
    cachedEl[i].style.display = "none";
}
pending…
Element (cached style visibility)
var i;
for(i = 0; cachedEl[i]; i++){
    cachedEl[i].style.visibility = "hidden";
}
pending…
jQuery :: visibility: hidden
$("div").css("visibility", "hidden");
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