

The big problem, for me, with using innertext to strip html tags was that it would remove script tags but leave the contents in-between the opening and closing script tag in your text content.

Using the javascript innertext property to remove HTML tags unfortunately doesn't work exactly how I wanted it too so I had to sweeten the deal with some regular expressions to get the text output I wanted. The Problem with Using InnerText to Remove HTML

Generally it's preferable to use an approach that leverages the DOM in a graceful way to find and remove the HTML content over an approach that just uses Regular Expressions to find and remove HTML tags.īecause you will encounter malformed HTML, the regex approach can fail in spectacular ways so here I tried to leverage the javascript innerText property to get the job done in a more dependable way.
#Javascript remove html tags code#
This is just a bit of a technical note about removing html elements using JavaScript code so if you're not into the technical details then just skip this part and use the html stripper tool above.
