A tricky one to dig out from a search engine as there is a lot of code out there to strip JavaScript and HTML tags but there are some interesting solutions.
The first runs through the string and builds a new one stopping when it is inside a tag:
code:
function stripHTML(oldString) {
var newString = "";
var inTag = false;
for(var i = 0; i < oldString.length; i++) {
if(oldString.charAt(i) == '<') inTag = true;
if(oldString.charAt(i) == '>') {
if(oldString.charAt(i+1)=="<")
{
//dont do anything
}
else
{
inTag = false;
i++;
}
}
if(!inTag) newString += oldString.charAt(i);
}
return newString;
}