jQuery show/hide vs css("display","none/block") (v34)

Revision 34 of this benchmark created on


Preparation HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="remove">
</div>
<script>
  $elem = $("#remove");
  var el = document.getElementById("remove");
  function showElement(element) {
    element[0].style.display = "block";
  }

  function hideElement(element) {
    element[0].style.display = "none";
  }
</script>
<style>
.displayNone{
    display:none;
}
</style>

Test runner

Ready to run.

Testing in
TestOps/sec
show/hide
$elem.show();
$elem.hide();
ready
jquery css
$elem.css("display", "block");
$elem.css("display", "none");
ready
css 1
$elem[0].style.display = "block"
$elem[0].style.display = "none";
ready
function
showElement($elem);
hideElement($elem);
ready
css 2
$elem.get(0).style.display = "block"
$elem.get(0).style.display = "none";
ready
jquery css {}
$elem.css({
  "display": "block"
});
$elem.css({
  "display": "none"
});
ready
jquery toggle
$elem.toggle();
ready
pure javascript
el.style.display = "block";
el.style.display = "none";
ready
jquery addclass
$elem.addClass("displayNone");
$elem.removeClass("displayNone");
ready

Revisions

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