title: JavaScript wrapping unwrapped plain text
body: <p>I have some non-static content on my webpage and I need all unwrapped plain text to be wrapped inside an anchor element with a class, however, I need to maintain the placement of that text.</p>
  
  <p>I've search around on this site and found questions like <a href="https://stackoverflow.com/questions/13836633/jquery-wrap-all-unwrapped-text-in-p-tags">these</a> which are asking the same question except the text is always in the beginning or the end and the answers always prepend/append the content back into the <code>&lt;div&gt;</code>.</p>
  
  <p>To make the question even more complicated, there are scenarios where the content will be only unwrapped plain text and I'll need to wrap that as well.</p>
  
  <p>My HTML:</p>
  
  <pre><code>&lt;div&gt;
    &lt;a&gt;1&lt;/a&gt;
    &lt;a&gt;2&lt;/a&gt;
    3
    &lt;a&gt;4&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Sometimes:</p>
  
  <pre><code>&lt;div&gt;
    1
  &lt;/div&gt;
  </code></pre>
  
  <p>I've tried all the answers on <a href="https://stackoverflow.com/questions/13836633/jquery-wrap-all-unwrapped-text-in-p-tags">this</a> page but they all reorder the text.</p>
  
  <p>Any ideas?</p>