I want to put "</script>" in a variable in JavaScript but it will be consider as end tag like below example:
<script>
content.value = aval + '<script> ma_gallery("' + varimgurl + '");</script>'+ sevom;
</script>
Does anyone know a solution ?
2 Answers 2
Use '<\/script>'.
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.
(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).
5 Comments
< will work/ is traditional, so it is the sensible choice.tSplit "</script>" into two strings:
content.value = aval + '<script> ma_gallery("' + varimgurl + '");</scr' + 'ipt>' + sevom;