title: How do I find line breaks and replace with <br> elements in JavaScript?
body: <p>I am trying to find and replace line breaks in text using javascript.</p>
  
  <p>The following works.  It replaces the character a with the character z.</p>
  
  <pre><code>var text = "aasdfasdf";
  text= text.replace(/a/g,"z");
  alert(text);
  </code></pre>
  
  <p>The following based on other posts on this and other message boards does not.  Basically the javascript does not fire:</p>
  
  <pre><code>var text = "aasdfasdf";
  text= text.replace(/\n/g,"z");
  alert(text);
  </code></pre>
  
  <p>...Here is one of many posts that suggests it should work.</p>
  
  <p><a href="https://stackoverflow.com/questions/863779/textarea-line-breaks-javascript">JavaScript: How to add line breaks to an HTML textarea?</a></p>
  
  <p>and by the way following does not work for me in Firefox either:</p>
  
  <pre><code>text = text.replace(/\n\r?/g, '&lt;br /&gt;'); or
  text = text.replace("\n", '&lt;br /&gt;'); 
  </code></pre>
  
  <p>Note: I realize there are no line breaks in the text variable..I am just using a simple string for testing purposes. </p>
  
  <p>Can anyone see what could be wrong or show me a way to do this that actually works.</p>
  
  <p>Thanks.  </p>