jQuery .remove vs. .hide vs. detach

JavaScript performance comparison

Revision 9 of this test case created

Preparation code

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<div id="remove-me">confirm removed</div>
<div id="hide-me">confirm hidden</div>
<div id="detach-me">confirm detatched</div>

<script>
  function init() {
   // The magic init() function will be executed once before every test
   // Still not perfect, but definitely better
   $('<div id="remove-me" />').appendTo('body');
   $('#hide-me').show();
   if (window.$detached != null) {
    window.$detached.appendTo('body');
   }
  }
</script>

Preparation code output

confirm removed
confirm hidden
confirm detatched

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
.remove()
window.$removed = $('#remove-me').remove();
pending…
.hide()
window.$hidden = $('#hide-me').hide();
pending…
.detach()
window.$detached = $('#detach-me').detach();
pending…
style.display
document.getElementById('hide-me').style.display = 'none';
pending…
document.getElementById('hide-me').style.display = 'block';
pending…
document.getElementById('hide-me').style.background = 'green';
pending…
document.getElementById('hide-me').style.background = 'none';
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:

1 comment

ddddddd commented :

dddddd

Add a comment