faqts : Computers : Programming : Languages : JavaScript : Language Core : Strings

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

73 of 91 people (80%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How do I use quotes inside a string?

Feb 7th, 2000 09:38
Martin Honnen,


JavaScript string constants are delimited by single or double quotes 
e.g.
  'a string'
or 
  "a string"
so obviously having quotes inside a string needs some escaping of the 
quotes to work unless you can live with using single quotes inside of 
double quotes and vice versa. Escaping is done with the backslash so
  "\""
or
  '\''
are strings with quotes.
JavaScript in a web context often handles html source string even 
containing js itself where escaping is particularly needed e.g.
  var html = 
    '<A HREF="javascript: alert(\'js alert\'); void 0">link</A>';
  document.write(html)