Escape $ to \\$ with Javascript replace regular expression
<p>I have a string of <code>"aa$bb$cc"</code>; and I want to replace it to be <code>"aa\$bb\$cc"</code><br>
I've tried this:</p>

<pre><code>var str = "aa$bb$cc"
str.replace(/$/g, "\\$"); 
</code></pre>

<p>But the outpus is <code>"aa$bb$cc\$"</code> </p>

<p>How can I replace it and get same (<em>correct...</em>) result in all browsers?</p>
