Reputation: 25
I am trying to build HTML in my javascript file this way.I need to add one more classname to my class attribute. But this classname is a javascript variable. I am not sure how to add this variable so that javascript interpolates this.
function build_html(sku)
{
//need to add sku as my classname here
tmpString += "<a href=\"javascript: void(0)\" class=\"cart sku\">ADD TO CART</a>";
}
TIA
Upvotes: 0
Views: 215
Reputation: 25397
Just use the + operator to concatenate strings:
function build_html(sku)
{
//need to add sku as my classname here
tmpString += "<a href=\"javascript: void(0)\" class=\"cart " + sku + "\">ADD TO CART</a>";
}
Upvotes: 1