Home » Categories » JavaScript

Strip HTML Tags in JavaScript

const originalString = `
  <div>
    <p>Hey that's <span>somthing</span></p>
  </div>
`;

const strippedString = originalString.replace(/(<([^>]+)>)/gi, "");

console.log(strippedString);

Reference:
https://css-tricks.com/snippets/javascript/strip-html-tags-in-javascript/
Article Rating (No Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
 
Attachments Attachments
There are no attachments for this article.
Comments Comments
There are no comments for this article. Be the first to post a comment.
Related Articles RSS Feed
Regex in Javascript to remove links
Viewed 467 times since Sat, Oct 3, 2020
How to hide image broken Icon using only CSS/HTML?
Viewed 734 times since Wed, Sep 30, 2020
Hidden image after redirect by check filename
Viewed 558 times since Wed, Sep 30, 2020
Check image width and height before upload with Javascript
Viewed 463 times since Mon, Sep 21, 2020
XMLHttpRequest.responseURL
Viewed 452 times since Wed, Sep 30, 2020
Get The Current Domain Name With Javascript (Not the path, etc.)
Viewed 524 times since Fri, Oct 2, 2020