TIMEX TIMEX - 3 months ago 37
Javascript Question

How do I add slashes to a string in Javascript?

Just a string. Add \' to it every time there is a single quote.

Answer

replace works for the first quote, so you need a tiny regular expression:

str = str.replace(/'/g, "\\'");