title: jQuery to remove &nbsp;s but without using .html() which re-creates everything
body: <p>I have lots of elements within CKEditor with events hooked up to them and data bound to them using the .data() method. I would like to remove any &ampnbsp;s from this block of HTML. I could simply do </p>
  
  <pre><code>$('body').html($('body').html().replace(/&amp;nbsp\;/, ''));
  </code></pre>
  
  <p>But because this resets the HTML it effectivly re-creates all of the elements which means that I have to re-bind all of the events and data. What I am currently doing is this:</p>
  
  <pre><code>if ($body.html().indexOf('&amp;nbsp;') &gt; -1) {
      $body.find(':*:not(:has(*))').each(function(){
              // These nodes don't have any children so contain text or nothing
              $(this).html($(this).html().replace(/&amp;nbsp\;/,''));
      });
  }
  </code></pre>
  
  <p>This will replace &ampnbsp;s in HTML like this:</p>
  
  <pre><code>     &lt;p&gt;Foo&amp;nbsp;Bar&lt;/p&gt;
  </code></pre>
  
  <p>But not in HTML like this:</p>
  
  <pre><code>     &lt;div&gt;Foo&amp;nbsp;&lt;span&gt;Bar&lt;/span&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Can anyone think of a better way of doing this?</p>
  
  <p>Thanks,</p>
  
  <p>Joe</p>