You can use the replace () method to avoid double quotes:
for (var i = 0; i < images.length; ++i) { gallery += '<img width="250" height="250" src="' + images[i].src + '" title="' + images[i].title.replace(/\"/g, '\\"') + '" />'; }
EDIT: The result will be a valid Javascript string, but will not work as HTML markup, because the HTML parser does not understand reverse reset screens. You will have to either replace the double quotes with single quotes in the image header:
for (var i = 0; i < images.length; ++i) { gallery += '<img width="250" height="250" src="' + images[i].src + '" title="' + images[i].title.replace(/\"/g, "'") + '" />'; }
Or invert the types of quotes in your markup:
for (var i = 0; i < images.length; ++i) { gallery += "<img width='250' height='250' src='" + images[i].src + "' title='" + images[i].title + "' />"; }
Frédéric hamidi
source share