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

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -