I’m struggling with a complex nested quotes statement here :
var name = "foo";
$("#list").append("<li data-theme='c'><a href='#details' onclick='sessionStorage.name=PRINT_VAR_NAME_HERE;' data-transition='slide'>PRINT_VAR_NAME_HERE</a></li>");
I am able to print the variable’s value fine in the second position by using : “+name+”
But not sure how to get it done in the first position.
(I have used ‘PRINT_VAR_NAME_HERE’ as a placeholder for the first and second positions)
Any ideas ? Thanks.
Just use the string-delimiters (the
") to break the string and concatenate the string with your variable, and escape (with the backslash) any quotes that you need to appear in the string itself:I am, of course, assuming that you want to quote the variable in the string, otherwise I couldn’t see what the problem would be.