Link to home
Start Free TrialLog in
Avatar of cabrera48
cabrera48

asked on

Unable to escape quotes on javascript

Why is the following code giving me an error message?

<a href="#"  onclick="javascript:alert('This is a \"quotes\" test');">Test quotes</a>

Isn't it the escape characters take care of not taking the quotes " as the end of the string?

This is the error message I am getting:

unterminated string literal
[Break on this error] alert('This is a \
ASKER CERTIFIED SOLUTION
Avatar of basicinstinct
basicinstinct
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or you can do it like this:

<a href="#"  onclick="javascript:alert('This is a ' + String.fromCharCode(34) + 'quotes' + String.fromCharCode(34) + ' test');">Test quotes</a>
Avatar of cabrera48
cabrera48

ASKER

String.fromCharCode(34)  works, thanks !!!