Alexander Shpindler Alexander Shpindler - 4 years ago 159
HTML Question

How to ignore HTML tags in innerHTML attribute?

I'm making a messenger and my messages don't ignore HTML tags because I simply past a text from input in innerHTML of message. My code:

function Message(sender) {
this["text"] = "";
this.addText = function (text) {
this["text"] = text;

And here I display it:

var chatMessageText = document.createElement("p");
chatMessageText.innerHTML = message["text"];

What can I do for ignoring HTML tags in message["text"]?

Answer Source

Update Node#innerText property(or Node#textContent property).

chatMessageText.innerText = message["text"];

Check the difference of both here : innerText vs textContent

Refer : Difference between text content vs inner text

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download