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