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.
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.
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: