jQuery: css-display:none vs. hide (v19)

Revision 19 of this benchmark created by art on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="hide-me">hide me</div>
<script>
  var cachedjQuery = $("#hide-me");
  var cachedEl = document.getElementById("hide-me");
  var cachedStyle = cachedEl.style;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery :: display: none
$("#hide-me").css("display", "none");
$("#hide-me").css("display", "block");
ready
jQuery :: hide()
$("#hide-me").hide();
$("#hide-me").show();
ready
jQuery :: display: none (cached)
cachedjQuery.css("display", "none");
cachedjQuery.css("display", "block");
ready
jQuery :: hide() (cached)
cachedjQuery.hide();
cachedjQuery.show();
ready
Element
document.getElementById("hide-me").style.display = "none";
document.getElementById("hide-me").style.display = "block";
ready
Element (cached)
cachedEl.style.display = "none";
cachedEl.style.display = "block";
ready
Element (cached style)
cachedStyle.display = "none";
cachedStyle.display = "block";
ready
Element (cached style visibility)
cachedStyle.visibility = "hidden";
cachedStyle.visibility = "visible";
ready
jQuery :: get (cached)
cachedjQuery.get(0).style.display = "none";
cachedjQuery.get(0).style.display = "block";
ready
jQuery is visible
if($("#hide-me").is(":hidden")) {
}
ready
native if visible
if(cachedStyle.visibility === "hidden") {
}
ready

Revisions

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