title: Find a word that appears several times in the same element
body: <p>Lets say I have the following HTML:</p>
  
  <pre><code>&lt;div&gt;
  &lt;p&gt;TEST TEST&lt;/p&gt;
  &lt;p&gt;TEST&lt;/p&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I would like to find and highlight all of the occurrences of the word TEST on one button click.</p>
  
  <p>I'm currently using a JS function to find and bold which is a mini-plugin:</p>
  
  <pre><code>function findAndBold(searchText, replacement, searchNode) {
      if (!searchText) {
          // Throw error here if you want...
          return;
      }
  
      var regex = typeof searchText === 'string' ? new RegExp(searchText, 'i') : searchText;
      var childNodes = (searchNode || document.getElementById("mainContent")).childNodes;
      var cnLength = childNodes.length;
  
  
      while (cnLength--) {
  
          var currentNode = childNodes[cnLength];
  
          if (currentNode.nodeType === 1) {
              arguments.callee(searchText, replacement, currentNode);
          }
  
          if (currentNode.nodeType !== 3 || !regex.test(currentNode.data)) {
              continue;
          }
  
          var parent = currentNode.parentNode;
  
          var frag = (function () {
              var boldText = "&lt;span style='background-color: yellow; display: inline;'&gt;" + searchText + "&lt;/span&gt;";
              var html = currentNode.data.replace(regex, boldText);
              var wrap = document.createElement('div');
              frag = document.createDocumentFragment();
              wrap.innerHTML = html;
              while (wrap.firstChild) {
                  frag.appendChild(wrap.firstChild);
              }
  
              return frag;
          })();
  
          parent.insertBefore(frag, currentNode);
          parent.removeChild(currentNode);
  
      }
  
  }
  </code></pre>
  
  <p>The problem with that function is that on the first click, it only finds the first occurrence of the word TEST in each Paragraph, and only if I click find again it will highlight the other TEST word.</p>
  
  <p>I hope someone can help. Thank you.</p>