title: Highlight search terms (select only leaf nodes)
body: <p>I would like to highlight search terms on a page, but not mess with any HTML tags.  I was thinking of something like:</p>
  
  <pre><code>$('.searchResult *').each(function() {
      $(this.html($(this).html().replace(new RegExp('(term)', 'gi'), '&lt;span class="highlight"&gt;$1&lt;/span&gt;'));
  )};
  </code></pre>
  
  <p>However, <code>$('.searchResult *').each</code> matches all elements, not just leaf nodes.  In other words, some of the elements matched have HTML inside them.  So I have a few questions:</p>
  
  <ol>
  <li>How can I match only leaf nodes?</li>
  <li>Is there some built-in jQuery RegEx function to simplify things?  Something like: <code>$(this).wrap('term', $('&lt;span /&gt;', { 'class': 'highlight' }))</code></li>
  <li>Is there a way to do a simple string replace and not a RegEx?</li>
  <li>Any other better/faster way of doing this?</li>
  </ol>
  
  <p>Thanks so much!</p>