Entry
How do I use quotes inside a string?
Feb 7th, 2000 09:38
Martin Honnen,
JavaScript string constants are delimited by single or double quotes
e.g.
'a string'
or
"a string"
so obviously having quotes inside a string needs some escaping of the
quotes to work unless you can live with using single quotes inside of
double quotes and vice versa. Escaping is done with the backslash so
"\""
or
'\''
are strings with quotes.
JavaScript in a web context often handles html source string even
containing js itself where escaping is particularly needed e.g.
var html =
'<A HREF="javascript: alert(\'js alert\'); void 0">link</A>';
document.write(html)