strip html tags from a string in Javascript


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <HTML>
  2. <HEAD>
  3. <TITLE> Regular Expressions: stripping HTML tags </TITLE>
  4. </HEAD>
  5. <BODY>
  6. <SCRIPT LANGUAGE="JavaScript">
  7. var htstring = '<p align="Left"><b>Hello</b> <I>World</I></p>';
  8. var stripped = htstring.replace(/(<([^>]+)>)/ig,"");
  9.  
  10. with (document) {
  11. write ('Original string:' + htstring + '<br>');
  12. write ('Stripped string:<br><br>' + stripped);
  13. }
  14. </SCRIPT>
  15. </BODY>
  16. </HTML>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.