html - JavaScript alert with escaped characters fail -


why following javascript fail, when click on link? , there way fix it?

<a onclick="alert('do want delete &lt; &gt; &quot; &#39;?');">link</a> 

i aware escaped characters illegal if printed literally, can't see why should fail when escaped. leaving out characters not option, user defined.

&#39; considered single quote, need escape \, \&#39;

without escaping, javascript throw "unterminated string literal" error.

this works:

<a onclick="alert('do want delete &lt; &gt; &quot; \&#39;?');">link</a> 

Comments