I want to remove HTML tags from a string. For example assume we have the string:
example ive got a string
How can I wr
The safest way is to rely on the browser TextNode to correctly escape content. Here's an example:
function stripHTML(dirtyString) {
var container = document.createElement('div');
var text = document.createTextNode(dirtyString);
container.appendChild(text);
return container.innerHTML; // innerHTML will be a xss safe string
}
document.write( stripHTML('some content
') );
document.write( stripHTML('