Mega Code Archive

 
Categories / JavaScript Tutorial / Regular Expressions
 

Strip HTML

< html> <head> <title>Strip HTML Example</title> <script type="text/javascript">     String.prototype.stripHTML = function () {         var reTag = /<(?:.|\s)*?>/g;         return this.replace(reTag, "");     };     function showText() {         var oInput1 = document.getElementById("txt1");         var oInput2 = document.getElementById("txt2");         oInput2.value = oInput1.value.stripHTML();     } </script> </head> <body> <textarea rows="10" cols="50" id="txt1"></textarea><br /> <input type="button" value="Strip HTML" onclick="showText()" /></p> <P>Stripped Text:<br /> <textarea rows="10" cols="50" id="txt2"></textarea></p> </body> </html>