title: getElementById replace HTML
body: <pre><code>&lt;script type="text/javascript"&gt;
     var haystackText = document.getElementById("navigation").innerHTML;
  
     var matchText = '&lt;a href="http://mydomain.co/?feed=rss"&gt;Subscribe to RSS&lt;/a&gt;';
  
     var replacementText = '&lt;ul&gt;&lt;li&gt;Some Other Thing Here&lt;/li&gt;&lt;/ul&gt;';
  
     var replaced = haystackText.replace(matchText, replacementText);
  
     document.getElementById("navigation").innerHTML = replaced;
  &lt;/script&gt;
  </code></pre>
  
  <p>I'm attempting to try and replace a string of HTML code to be something else. I cannot edit the code directly, so I'm using Javascript to alter the code.</p>
  
  <p>If I use the above method Matching Text on a regular string, such as <em>just</em> 'Subscribe to RSS', I can replace it fine. However, once I try to replace an HTML string, the code 'fails'.</p>
  
  <p>Also, what if the HTML I wish to replace contains line breaks? How would I search for that?</p>
  
  <pre><code>&lt;ul&gt;&lt;li&gt;\n&lt;/li&gt;&lt;/ul&gt;
  </code></pre>
  
  <p>??</p>
  
  <p>What should I be using or doing instead of this? Or am I just missing a small step? I did search around here, but maybe my keywords for the search weren't optimal to find a result that fit my situation...</p>
  
  <p>Edit: Gonna mention, I'm writing this script in the footer of my page, well after the text I wish to replace, so it's not an issue of the script being written before what I want to overwrite to appear. :)</p>