javascript - Which quotes to use in string literal nested in another string -
i have in jquery function change html-content in div, problem there onclick-function in it. not know quote tags use.
[q] = quote tag, not know
$("#container div").html("<div id='overlay' onclick='gofullscreen([q]video1[q])'></div>");
escape quotes:
quotes in strings should preceded backslash. allows javascript interpreter distinguish quote within string quotes serve string delimiters.
$("#container div").html("<div id='overlay' onclick=\"gofullscreen('video1')\"></div>"); // ^^ ^ ^ ^^
or
$("#container div").html("<div id='overlay' onclick='gofullscreen(\"video1\")'></div>"); // ^ ^^ ^^
examples
string1='it\'s 5 o\'clock!'; string2="<a href=\"index.htm\">";
alternatively, if string includes single quotes only, can use double quotes string delimiters, , vice versa. here's example:
string1="it's 5 o'clock!"; string2='<a href="index.htm">';
update
if video1
variable:
$("#container div").html("<div id='overlay' onclick=\"gofullscreen('" + video1 + "')\"></div>"); // ^^ ^^ ^ ^^ ^^
Comments
Post a Comment