This might sound silly but i’m having trouble printing a variable in this code –
var clsuffix = "something";
$("#box").wrap('<div class="boxy" />');
I want to print the clsuffix variable inside the class=” here ”
so it could be like
<div class="boxysomething">
But when i use the variable inside class=””, it comes up as it is (not being treated as variable)
Just concatenate it in. Ultimately, your goal is to build a string consisting of the literal
"boxy"and the contents of the variableclsuffix. That is done with"boxy" + clsuffixin JavaScript:If you were just trying to insert the variable into the string (such as you might do in a PHP double-quoted string), it won’t be interpreted by JavaScript: