title: Unexpected Character > when appending html - regex escape necessary?
body: <p>I wonder if someone can help me understand. I was getting an AJAX response of HTML and adding it to the DOM with jQuery's .appendTo(), and getting the error:</p>
  
  <p>"Unexpected character >". </p>
  
  <p>After plenty of Googling and elimination debugging, I discovered it was a JavaScript function:</p>
  
  <pre><code>function htmlEscape(str) {
    return String(str)
        .replace(/&amp;/g, '&amp;amp;')
        .replace(/"/g, '&amp;quot;')
        .replace(/'/g, '&amp;#39;')
        .replace(/&lt;/g, '&amp;lt;')
        .replace(/&gt;/g, '&amp;gt;');
  }
  </code></pre>
  
  <p>Note the final replace. If I escape that right chevron, I'm good. I ran my code through a syntax checker early on (<a href="http://esprima.org/demo/validate.html" rel="nofollow noreferrer">http://esprima.org/demo/validate.html</a>) and it said everything was valid. So I wonder if anyone can explain why this issue arose?</p>
  
  <p>Thanks!</p>