GibboK
GibboK

Reputation: 74008

Escaping character string

I need to modify var absolute to use var y instead of a static value xxxxxx.

I have problem with js escpainig.

        var y = 'http://www.mysite.com';
var resp = '<div><img src="smiley1.gif"></div><div><img src="smiley2.gif"></div><div><img src="smiley3.gif"></div>';               
        var re = /src=\"/gi;
        var absolute = "src=\"xxxxxx\/"; // replace xxxxxx with value from variable y
        resp = resp.replace(re, absolute);

trying

var absolute = "src=\"+ y +/";

does not work.

Any idea what is wrong?

Upvotes: 0

Views: 57

Answers (2)

&#201;douard Lopez
&#201;douard Lopez

Reputation: 43419

I don't see why you need the (back)slash for. Use simple quote instead:

var absolute = 'src="'+ y +'"';

Upvotes: 1

GibboK
GibboK

Reputation: 74008

fixed in this way

'src=\"' + y + '\/';

Upvotes: 1

Related Questions