title: How to replace a specific tag content in javascript
body: <p>I have a string, <strong>that may or may not be valid HTML</strong>, but it should contain a Title tag.<br>
  I want to replace the content of the title with new content.  </p>
  
  <p>Example 1:  </p>
  
  <pre><code>lorem yada yada &lt;title&gt;Foo&lt;/title&gt; ipsum yada yada  
  </code></pre>
  
  <p>Should turn into:</p>
  
  <pre><code>lorem yada yada &lt;title&gt;Bar&lt;/title&gt; ipsum yada yada  
  </code></pre>
  
  <p>Example 2:</p>
  
  <pre><code>lorem yada yada &lt;title attributeName="value"&gt;Foo&lt;/title&gt; ipsum yada yada  
  </code></pre>
  
  <p>Should turn into:</p>
  
  <pre><code>lorem yada yada &lt;title attributeName="value"&gt;Bar&lt;/title&gt; ipsum yada yada  
  </code></pre>
  
  <p>I don't want to parse html with regex - just replace the title tag... Please don't send me <a href="https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags">here</a>...</p>
  
  <p>EDIT: 
  After numerous down votes and a lot of patronizing attitude -<br>
  I am aware (as admitted in the original post) that usually Regex is not the way to handle HTML. I am open to any solution that will solve my problem, but till now every JQuery / DOM solution did not work. Being "right" is not enough.</p>