title: Javascript Replace() and innerHTML
body: <p>I have this code: [it is a rough example with poor coding, but it illustrates what I want to do.]</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;script type="text/javascript"&gt;
  
      function fun()
      {
         var divs = document.getElementById('hi');
         divs.innerHTML = divs.innerHTML.replace("cake","jump");
         alert(divs.innerHTML);
      }
  
      &lt;/script&gt;
  
      &lt;div id="hi"&gt;
         &lt;span onclick="fun('cake');"&gt;Mer&lt;span onclick="fun('cake');"&gt;Mer&lt;/span&gt;&lt;/span&gt;
      &lt;/div&gt;
      &lt;a onclick='fun()';)&gt;Click&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I click on the <code>&lt;a&gt;</code> i want to change the onclick parameter within fun() from 'cake' to 'jump'.  I do not want to use the setAttribute() method as my real example has several nested tags and I want to replace 'cake' in several different places.</p>
  
  <p>I want the innerHTML.replace() function to work to do this but, alas it doesn't function as I want it to.  How do I replace text within innerHTML?</p>