2

Possible Duplicates:
Escape single quotes in jQuery or JavaScript
Escape dynamic strings in JavaScript

How do you assign a string, in this case it's HTML code, to a JavaScript / jQuery variable?

And how do you escape double quotes and single quotes properly?

var html = ""; // <-- HTML goes here
1
  • 2
    Could you please clarify your question further, maybe include an full example of what exactly it is your trying to accomplish? As it stands I have no idea what your asking. Commented Dec 20, 2011 at 21:56

1 Answer 1

11

var html = "<head><title>Hello in \"quotes\"<\/title><\/head>"

Sign up to request clarification or add additional context in comments.

2 Comments

Note that js strings can be delimited by single quotes or double quotes, and chars of the non-delimiting quote type do not need to be escaped. That is, both var html = '<head><title>Hello in "quotes"<\/title><\/head> and var html = "<head><title>Hello in 'quotes'<\/title><\/head>" are valid without escaping any characters in the string. See String Literals at MDN for more about it.
of course, I just wanted to show an example of how escaping works in a string

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.