title: Javascript - Replace html using innerHTML
body: <p>I'm trying to replace html using innerHTML javascript.</p>
  
  <p>From:</p>
  
  <pre><code>aaaaaa/cat/bbbbbb
  </code></pre>
  
  <p>To:</p>
  
  <pre><code>&lt;a href="http://www.google.com/cat/world"&gt;Helloworld&lt;/a&gt;
  </code></pre>
  
  <p>This's my code</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p id="element1"&gt;aaaaaa/cat/bbbbbb&lt;/p&gt;
  
  &lt;script language="javascript"&gt;
  var strMessage1 = document.getElementById("element1") ;
  strMessage1.innerHTML = strMessage1.innerHTML.replace( /aaaaaa./g,'&lt;a href=\"http://www.google.com/') ;
  strMessage1.innerHTML = strMessage1.innerHTML.replace( /.bbbbbb/g,'/world\"&gt;Helloworld&lt;/a&gt;') ;
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When i run this code it disappears Helloworld hyperlink.
  what I'm doing wrong. Please help.</p>
  
  <p>Thank you for all your help.</p>