Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to remove html tags from a string in JavaScript? [duplicate]

I am working with the rich text editor component of primeng. This editor turns everything i type in into html. But sometimes i want to output these texts in plain text instead. Does angular 2 provide a way to easily remove the html tags from the text?

Thank you.

like image 599
Maurice Avatar asked Jul 05 '18 15:07

Maurice


People also ask

Is it possible to remove the HTML tags from data?

Strip_tags() is a function that allows you to strip out all HTML and PHP tags from a given string (parameter one), however you can also use parameter two to specify a list of HTML tags you want.

How do I remove a tag from a string?

The HTML tags can be removed from a given string by using replaceAll() method of String class. We can remove the HTML tags from a given string by using a regular expression. After removing the HTML tags from a string, it will return a string as normal text.

What is strip HTML?

stripHtml( html ) Changes the provided HTML string into a plain text string by converting <br> , <p> , and <div> to line breaks, stripping all other tags, and converting escaped characters into their display values.

How remove HTML tag from string in react?

To remove html tags from string in react js, just use the /(<([^>]+)>)/ig regex with replace() method it will remove tags with their attribute and return new string.


1 Answers

You can achieve this by JavaScript.

Try this!!

var plainText = content.replace(/<[^>]*>/g, '');

This will return you plain text.

like image 74
Surjeet Bhadauriya Avatar answered Oct 08 '22 23:10

Surjeet Bhadauriya