TIMEX TIMEX - 9 months ago 102
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, "\\'");