title: Replace content in elements without replacing HTML
body: <p>Suppose I have the following HTML structure:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;test&gt;
      &lt;div&gt;
          This is a test
          &lt;/div&gt;
      &lt;div&gt;
          This is another test
          &lt;button&gt;
              Button test
          &lt;/button&gt;
      &lt;/div&gt;
  &lt;/test&gt;
  </code></pre>
  
  <p>Now I use the following jQuery code to replace, e.g., 'T':</p>
  
  <pre class="lang-js prettyprint-override"><code>$("test *").each(function(index, value) {
      $(this).html($(this).html().replace(new RegExp('t', "ig"), "&lt;b&gt;t&lt;/b&gt;"));
  });
  </code></pre>
  
  <p>However, this results in the following HTML structure (which is unexpected, see the <code>&lt;button&gt;</code> tag, which breaks my HTML):</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;test&gt;
      &lt;div&gt;
          &lt;b&gt;T&lt;/b&gt;his is a &lt;b&gt;t&lt;/b&gt;es&lt;b&gt;t&lt;/b&gt;
          &lt;/div&gt;
      &lt;div&gt;
          &lt;b&gt;T&lt;/b&gt;his is ano&lt;b&gt;t&lt;/b&gt;her &lt;b&gt;t&lt;/b&gt;es&lt;b&gt;t&lt;/b&gt;
          &lt;bu&lt;b&gt;t&lt;/b&gt;&lt;b&gt;t&lt;/b&gt;on&gt;
              Bu&lt;b&gt;t&lt;/b&gt;&lt;b&gt;t&lt;/b&gt;on &lt;b&gt;t&lt;/b&gt;es&lt;b&gt;t&lt;/b&gt;
              &lt;/bu&lt;b&gt;t&lt;/b&gt;&lt;b&gt;t&lt;/b&gt;on&gt;
          &lt;/div&gt;
      &lt;/test&gt;
  </code></pre>
  
  <p>What I want to achieve is:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;test&gt;
      &lt;div&gt;
          &lt;b&gt;T&lt;/b&gt;his is a &lt;b&gt;t&lt;/b&gt;es&lt;b&gt;t&lt;/b&gt;
          &lt;/div&gt;
      &lt;div&gt;
          &lt;b&gt;T&lt;/b&gt;his is ano&lt;b&gt;t&lt;/b&gt;her &lt;b&gt;t&lt;/b&gt;es&lt;b&gt;t&lt;/b&gt;
          &lt;button&gt;
              Bu&lt;b&gt;t&lt;/b&gt;&lt;b&gt;t&lt;/b&gt;on &lt;b&gt;t&lt;/b&gt;es&lt;b&gt;t&lt;/b&gt;
              &lt;/button&gt;
          &lt;/div&gt;
      &lt;/test&gt;
  </code></pre>
  
  <p>Basically, I want to replace within the entire element but preserve the HTML tags and all the HTML attributes.</p>