Reputation: 5007
If i get the .val() from a text input, how can I make sure there is no HTML in there and just plain text?
I am writing a small chat program but I dont want users to be able to enter HTML.
Upvotes: 2
Views: 4154
Reputation: 2034
You can do it by getting the textContent of the HTML they enter:
// Get the value of the input
var inputText = $('#my-input').val();
// Store only the text and no HTML elements.
inputText = $(inputText)[0].textContent;
Here is an example:
http://jsfiddle.net/thom801/5A3sQ/1/
Upvotes: 2