Posts Tagged: escape ‘ javascript


14
Jan 08

Escape single quotes(‘) in JavaScript

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” .