Rendering strings containing HTML entities would require special attention as browser can only understand HTML tags and are formatted according to the HTML entities. So this post will help in dealing with such cases which will render HTML entities as plain text in browser.
This is the major function that does the espcaping of HTML entities. As you can see it require an entityMap which contains all HTML entities that you want to require.
So here is our enitityMap:
As you can notice that these are the possible basic HTML entities, you can convert them to escape string that browser understands as plain text.
So what next:
We are all ready and I am giving you a sample text to test this.
text = escapeHtml(text); $("#demo").html(text);
When you do all the above mentioned steps correctly, you would get the following result.
Observe that all HTML tags are restored as it is.
Still having a problem you can check our live demo over here.