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>"); //                                                  ^^             ^     ^ ^^ 

demo

or

$("#container div").html("<div id='overlay' onclick='gofullscreen(\"video1\")'></div>"); //                                                  ^             ^^      ^^ 

demo

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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -