title: How to revert a converted text string back to original HTML layout?
body: <p>This question is derived from the accepted answer of <a href="https://stackoverflow.com/questions/32975831/jquery-how-to-replace-one-word-in-a-div/32975947">Jquery - How to replace one word in a div?</a></p>
  
  <p>The code below will detect a specific word in a <code>&lt;div&gt;</code>, change the detected word into another word, and then render the everything in the <code>&lt;div&gt;</code> using the <code>.text()</code> method.  Although this is a viable solution, is there perhaps a way to automatically convert the text string back to the original HTML layout format while retaining the newly created text string?</p>
  
  <p>That is to say, the new output should maintain the line breaks<code>&lt;br/&gt;</code>, but it should not be limited to them only (all HTML should be kept).</p>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;div class="dealer-addy"&gt;
      8726 N. Royal Ln&lt;br&gt;
      Irving, TX  75063&lt;br&gt;
      email@aol.com
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>jQuery:</strong></p>
  
  <pre><code>var text = $(".dealer-addy").text(); 
  
  function extractEmails ( text ){
      return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi) ;
  }
  
  var email = extractEmails(text);
  var value = $(".dealer-addy").text();
  
  value = value.replace(email, "new@email.com"); 
  $(".dealer-addy").text(value);
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>8726 N. Royal Ln Irving, TX 75063 new@email.com
  </code></pre>
  
  <p><strong>Desired Output:</strong></p>
  
  <pre><code>8726 N. Royal Ln&lt;br/&gt;
  Irving, TX 75063&lt;br/&gt;
  new@email.com
  </code></pre>
  
  <p><a href="http://jsfiddle.net/VS7Qe/166/" rel="nofollow noreferrer">Fiddle</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var text = $(".dealer-addy").text(); 
  
  function extractEmails ( text ){
      return text.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi) ;
  }
  
  var email = extractEmails(text);
  var value = $(".dealer-addy").text();
  
  value = value.replace(email, "new@email.com"); 
  $(".dealer-addy").text(value);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="dealer-addy"&gt;
    8726 N. Royal Ln&lt;br&gt;
    Irving, TX 75063&lt;br&gt;
    email@aol.com
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>