jQuery .remove vs. .hide vs. detach

JavaScript performance comparison

Revision 4 of this test case created by tenbits

Preparation code

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

<div id="remove-me"></div>
<div id="hide-me"></div>
<div id="detach-me"></div>

  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');
   if (window.$detached != null) {

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
window.$removed = $('#remove-me').remove();
window.$hidden = $('#hide-me').hide();
window.$detached = $('#detach-me').detach();

Compare results of other browsers


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

mike commented :

very cool thanks for the test

Comment form temporarily disabled.

Add a comment