I am using Ajax to post the comments of the website.
No the user can also write some scripts inside a textbox.
The problem is I want to HTML encode it (REMOVE html tags,scripts ETC).
Means remove the html elements.
As far as now i make an unsuccessful try as:
var textData = $("'" + $('#textBox').val() + "'").text();
But this is a ridiculous attempt by me. Though it sometimes work but it MAY fail with special symbols etc.
Any help is this regard is deeply appreciated.
Thank You.
EDIT:
Whenever the user post the comment i send the comment to server and at the server side encode it and save it to DB and also on client side update my HTML. I dont want to get the encoded message back from the server
As everyone else said, please don’t do this. Solve it on the server.
However, the shortest way to just HTML encode whatever was send (that is, actually print out
<b>x</b>is this: