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?
You really have three options.
Use the opposite quote style, in this case single quotes, to surround the attribute declaration.
var test = "<div id='"+replyName+"' class='"+replyName+"'></div>";
Use escaped quotes.
var test = "<div id=\""+replyName+"\" class=\""+replyName+"\"></div>";
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.
var test = "<div id="+replyName+" class="+replyName+"></div>"
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.