There may be instances where you need to display single quotes in an alert box. Or may be double quotes too. To have these displayed without any errors all you need to do is add a backslash “\” before the single quote or double quote. That’s it!!!
Example: alert(“Hi! Welcome to my \’blog\’. This can also be displayed as \”blog\”.”);
The output in the alert window will be:
Hi! Welcome to my ‘blog’. This can also be displayed as “blog” .
Tags: escape ' javascript, escape ' js, escape double quotes javascipt, escape single quote javascript
Can you explain how to make this work? basically I want to display an alert on the click of an element that has both single and double quotes in the text. Thanks!
click for alert
ok, suppose the text to be displayed in the alert is – I love ‘Java’ and this is my “Blog”. You would write this as
alert(“I love \’Java\’ and this is my \”Blog\” “);
This is the safest way to write. Hope you get it
I have a link that calls a javascript function within a php page. I’m trying to find a way to make it work, but I think it keeps breaking at the single quote:
Server Info
I’ve tried heredoc as well, but that didn’t resolve the issue either.