Reputation: 658
Why does the following JavaScript fail, when you click on the link? And is there any way to fix it?
<a onclick="alert('Do you want to delete < > " '?');">Link</a>
I am aware that the escaped characters would be illegal if they were printed literally, but I can't see why it should fail when then are escaped. Leaving out the characters is not an option, as it is user defined.
Upvotes: 0
Views: 4120
Reputation: 30989
'
is considered a single quote, you need to escape it with a \
, so \'
Without escaping, javascript will throw an "unterminated string literal" error.
This works:
<a onclick="alert('Do you want to delete < > " \'?');">Link</a>
Upvotes: 2