If I use the following then it is displayed like html:
<h1>heading</h1>
This will be the result:
heading
But how do I unescape all the characters inside <code>
?
Which results exactly what inside the <code>
:
<h1>heading</h1>
If I use the following then it is displayed like html:
<h1>heading</h1>
This will be the result:
But how do I unescape all the characters inside <code>
?
Which results exactly what inside the <code>
:
<h1>heading</h1>
Either replace the tag syntax with HTML entities
str = '<foo>';
str = str.replace(/</g, '<').replace(/>/g, '>');
str; // "<foo>"
Or insert it into the page explicitly as text, e.g.
parent.appendChild(document.createTextNode(str));
You may also wish to escape single and double quotes to be on the safe side if you plan to use random strings in attributes, too.
str = str.replace(/"/g, '"').replace(/'/g, ''');
` is that enough to replace just greater and smaller signs only?
– Navin Rauniyar
Jul 08 '14 at 10:58