Q: JQuery html code in JavaScript variable does not work Hi I have a Simple HTML line of code.
<li class="active"><a href="javascript:" onclick="jQuery(this).siblings().toggleClass('opened');">Show All<i class="fa fa-angle-down"></i></a>

Now I need to place this code in JavaScript Variable and unfortunately it does not work here.
var value = '<li class="active"><a href="javascript:" onclick="jQuery(this).siblings().toggleClass('opened');">Show All <i class="fa fa-angle-down"></i></a>';

Can anyone help me how to keep html code into JavaScript Variable. The issue is in the onclick function. 
Any Help will be appreciated. Thanks

A: Perhaps try escaping the single quotes. Because your string begins and ends with single quotes, it is ending your string before you want it to. See the highlighting in your question, where the text is black, the string has terminated.
var value = '<li class="active"><a href="javascript:" onclick="jQuery(this).siblings().toggleClass(\'opened\');">Show All <i class="fa fa-angle-down"></i></a>';


A: In this case you have to use escape sequence.
Try the following code: jQuery(this).siblings().toggleClass(\'opened\');


var value = '<li class="active"><a href="javascript:" onclick="jQuery(this).siblings().toggleClass(\'opened\');">Show All <i class="fa fa-angle-down"></i></a><a href="javascript:">something <i class="fa fa-angle-down"></i></a>';

$("#dum").html(value)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="dum"></div>



A: Your single quotes are breaking the code. You can use backticks to avoid this:


var value = `<li class="active"><a href="javascript:"onclick="jQuery(this).siblings().toggleClass('opened');">Show All <i class="fa fa-angle-down"></i></a>`;
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<li class="active"><a href="javascript:" onclick="jQuery(this).siblings().toggleClass('opened');">Show All<i class="fa fa-angle-down"></i></a>


