A little regular expression to remove all HTML tags from a string.
<h2>About</h2>
<p>Here you will find posts about news, trends and developing for internet,
mainly focusing on browsers and web user interfaces.</p>
<p><a href="/about">Read more</a></p>
About
Here you will find posts about news, trends and developing for internet,
mainly focusing on browsers and web user interfaces.
Read more
function removeHTMLTags(){
if(document.getElementById && document.getElementById("input-code")){
var strInputCode = document.getElementById("input-code").innerHTML;
/*
This line is optional, it replaces escaped brackets with real ones,
i.e. < is replaced with < and > is replaced with >
*/
strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
return (p1 == "lt")? "<" : ">";
});
var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
alert("Input code:\n" + strInputCode + "\n\nOutput text:\n" + strTagStrippedText);
}
}