Skip to content
Advertisement

String doesn’t accept the close tag for

I am building a code-editor, and below is my code:

JavaScript

Inside my onkeyup function in the writeln command, with the above string I get this error:

JavaScript

But then if I remove the </script> tag from the string it works. I don’t know why it doesn’t accept the close tag.

Can anyone explain this to me? Is there any way to make it accept the </script> tag?

Advertisement

Answer

You need it to break the </script> into "<" + "/script>" so that the HTML parser doesn’t interpret it as the closing tag. You can also do </script>.

An example of how it works:

JavaScript

And an example of how it wouldn’t work (with plain </script> which would be interpreted as the closing tag):

JavaScript

And if you want to use it inside back quotes, still the same (adding this per OP’s comment):

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement