I have the following code
var replyName = "1";
var test = "<div id=replyName></div>"
I want to set the class name to the variable replyName, what should I do?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You really have three options.
Use the opposite quote style, in this case single quotes, to surround the attribute declaration.
Use escaped quotes.
Use no quotes (beware this can cause problems if you have spaces, for instance, although an ID should not have spaces anyways). However, multiple classes would have spaces, so be careful, since in the below case those spaces would be interpreted as different attributes.
I would use 1 or 2, although 3 is valid under the right conditions.
Also, as Mikola mentions in a comment below, if you flip the string quote style to single quotes, you’ll have to use the opposite quoted style for your attribute a la 1, and escape single quotes like I do double quotes in 2.
http://jsfiddle.net/XyVuN/1/