how do you do html encode using javascript?

JavascriptHtml Encode

Javascript Problem Overview


> Possible Duplicate:
> JavaScript/jQuery HTML Encoding

I have html tags need to be encoded.

<b>test</b>

I need to encode it to :

&lt;b&gt;test&lt;/b&gt;

I am using escape, but it doesn't work.

document.write(escape("<b>test</b>"));

the result I got is

%3Cb%3Etest%3C/b%3E

this is not what I expected. is there another way to do html encode using javascript?

Javascript Solutions


Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionqinking126View Question on Stackoverflow