du*****@gmail.com writes:
I have a problem of escaping quotes in javascript.
Nope :)
onclick='alert( "Mister O'Hara" )'
onclick='alert( "Mister O\'Hara" )'
both gives me an error. How would I escape this?
Your problem is that the outer (single-)quotes are not Javascript
quotes, but HTML quotes. It is the HTML parser that barfs over your
code, not Javascript, so you would need an HTML escape, not the
Javascript escape.
The HTML "escape" of a single quote is the entity ',
so
onclick='alert("Mister O'Hara");'
Alternatively, you could use double quotes in HTML and single in
Javascript, and then use a Javascript escape:
onclick="alert('Mister O\'Hara');"
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'