Strip HTML Tags from String

This Javascript function removes all HTML tags from a string. If a user submits comments or other content, HTML tags need to be stripped in order control formatting. This function removes any potentially harmful code or user formatted code so your input is clean.

function strip_tags(i) {
	var tmp = document.createElement("DIV");
	tmp.innerHTML = i;
	return tmp.textContent||tmp.innerText;
}

Example:

textcomment = "Hello, my name is <b onclick='alert(\"hi\")>George</b> and I will insert some javascript into my text.";
textcomment = strip_tags(textcomment);

Produces the result: 

textcomment == "Hello, my name is George and I will insert some javascript into my text."