jQuery .remove vs. .hide vs. detach (v14)

Revision 14 of this benchmark created on


Preparation HTML

<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');
   window.$element = $('#hide-me').show();
   if (window.$detached != null) {
    window.$detached.appendTo('body');
   }
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
.remove()
$('#remove-me').remove();
ready
.hide()
$('#hide-me').hide();
ready
.detach()
$('#detach-me').detach();
ready
style.display
document.getElementById('hide-me').style.display = 'none';
ready
.css()
$('#hide-me').css('display', 'none');
ready
.css() without lookup
window.$element.css('display', 'none');
ready
style.display with jQuery
$('#hide-me')[0].style.display = 'none'
ready
style.display without lookup
window.$element[0].style.display = 'none'
ready
style.display with getElementById && jQuery
$(document.getElementById('hide-me'))[0].style.display = 'none';
ready
style.display with querySelector
document.querySelector('#hide-me').style.display = 'none';
ready

Revisions

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