Remove Empty Elements: Javascript vs jQuery

Benchmark created by Jon Quach on


Preparation HTML

<p></p><p>Stuffff</p><p></p><p></p><p>MORE STUFFF</p>

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

Test runner

Ready to run.

Testing in
TestOps/sec
Javascript
        var removeEmptyParagraphs = function() {
          var p = document.querySelectorAll('p:empty');
          for (var i = p.length - 1; i > -1; i--) {
            p[i].parentNode.removeChild(p[i]);
          }
        };
        removeEmptyParagraphs();
ready
jQuery
        var removeEmptyParagraphs = function() {
          $('p:empty').remove();
        };
        removeEmptyParagraphs();
ready

Revisions

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

  • Revision 1: published by Jon Quach on