title: Stripping useless elements from the DOM
body: <p>I want to strip all elements within the DOM that contains useless spaces or are empty (I'm working with an outdated back-end system that generates some messy HTML and these elements can sometimes add unwanted spaces in the design). Using the filter function I'm able to test for specific cases but for some reason it doesn't seem to work with empty elements so I tried to test to see if any elements length is &lt; 0 and then remove it. Why doesn't this work, and is there a way to do it with the filter function? I've tried </p>
  
  <pre><code>    ("&amp;lt;br&amp;gt;", "", "&amp;nbsp;");
  </code></pre>
  
  <p>but it doesn't seem to work.</p>
  
  <pre><code>stripEmpties();
  
  function stripEmpties() {
      var domChildren = $("*").children();
      if (domChildren.length &lt;= 0) {
          $(this).remove();
      } else {
          domChildren.filter(function () {
              return $.trim(this.innerHTML) === ("&amp;lt;br&amp;gt;", "&amp;nbsp;");
          }).remove();
      }
  }
  </code></pre>
  
  <p>Actually after playing with it I now see that only the last match is even used in the filter so it looks like I can't use this list format I've come up with. So I guess another question would be is there a way to get similar functionality while checking multiple cases with the filter function?</p>