TIMEX TIMEX - 1 year ago 125
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 Source

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

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