I'm asking about escaping such string:
function my(mstr){alert(mstr);};
document.getElementById('home').innerHTML = '<button onclick="my("a")">a</button>'
We have '<... onclick="fun("a")"...>'
so its double quotes inside of double quotes inside of single quotes.
Simple '<button onclick="my(\"a\")">...'
gives syntax error.
I know that i could escape it like
'<button onclick="my(\'a\')">...'
but i wonder why this syntax error appears.
EDIT: here's jsfiddle for it http://jsfiddle.net/pVy9W/1/
EDIT2: BallBin said it renders <button onclick="my("a")">a</button>
so
trying to escape backslash:
'<button type="button" onclick="my(\\\"a\\\")">a</button>';
it renders as strange:
<button type="button" onclick="my(\" a\")"="">a</button>
and gives error:
Uncaught SyntaxError: Unexpected token ILLEGAL