\" in a variable in JavaScript", "text": "<p>I want to put "<code></script></code>" in a variable in JavaScript but it will be consider as end tag like below example:</p>\n\n<pre class="prettyprint"><code><script> \ncontent.value = aval + '<script> ma_gallery("' + varimgurl + '");</script>'+ sevom;\n</script>\n</code></pre>\n\n<p>Does anyone know a solution ?</p>", "answerCount": 2, "upvoteCount": 718, "dateCreated": "2014-07-22 16:03:57", "dateModified": "2022-10-05 00:21:05", "author": { "type": "Person", "name": "M.Arjmandi" }, "acceptedAnswer": { "@type": "Answer", "text": "<p>Use <code>'<\\/script>'</code>.</p>\n\n<p>In a string literal, an escaped slash is equivalent to a slash so it makes no difference to the JavaScript parser but it breaks up the end tag syntax so it isn't parsed as an end tag by the HTML parser.</p>\n\n<p>(An alternative is to split it up into two strings and concatenate them together, but that is more typing, harder to read, and (albeit not significantly) less efficient).</p>", "upvoteCount": 122, "url": "https://exchangetuts.com/put-script-in-a-variable-in-javascript-1641121624940678#answer-1657674914752260", "dateCreated": "2022-10-03 11:21:05", "dateModified": "2022-10-05 00:21:05", "author": { "type": "Person", "name": "Quentin" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "<p>Split <code>"</script>"</code> into two strings:</p>\n\n<pre class="prettyprint"><code>content.value = aval + '<script> ma_gallery("' + varimgurl + '");</scr' + 'ipt>' + sevom;\n</code></pre>", "upvoteCount": 22, "url": "https://exchangetuts.com/put-script-in-a-variable-in-javascript-1641121624940678#answer-1657674914755470", "dateCreated": "2022-10-03 11:21:05", "dateModified": "2022-10-05 00:21:05", "author": { "type": "Person", "name": "Danilo Valente" } } ] } }