jquery - empty vs html (v20)

Revision 20 of this benchmark created on


Preparation HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div id="foo">foo bar foo bar foo bar foo bar</div>
<script>
  var foo = $('#foo');

  jQuery.fn.removeAll = function() {
   this.each(function() {
    var newEl = this.cloneNode(false);
   if (this.parentNode) this.parentNode.replaceChild(newEl, this);
     });
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
empty
foo.empty();
ready
html
foo.html('');
ready
innerHTML
foo[0].innerHTML = '';
ready
removeAll
foo.removeAll();
ready
DOM
document.getElementById('foo').innerHTML = '';
ready
textContent
foo[0].textContent = '';
ready

Revisions

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