Remove HTML and XML tags from string in Javascript

When you want to get the raw text from a string but it included the HTML or XML tags like this case:

We can do that easy with the function bellow:


In the function above, we create a new wrapper element (div) with createElement method and use the innerHTML method to render the HTML string then get raw text content by textContent or innerText method.

© 2019 4codev

Created with love by Sil.