[Javascript] How can I strip all the HTML tags from a given string?


I want to strip all the HTML tags from a given string, Is there any simple way to strip all the tags in Javascript?

1 Answer

3 years ago by

Use regex to strip all the HTML tags from the given string as shown below:

let str= `<!DOCTYPE html>
<html>
  <head>
    <title>Hello World!</title>
  </head>
  <body>
      <h1 class="title">Hello World! </h1>
  </body>
</html>`;

console.log(str.replace( /(<([^>]+)>)/ig, ''));

Run here https://onecompiler.com/javascript/3xns38q79

3 years ago by Meera