is it possible to use the jquery text() function to remove all HTML in a string?
String with HTML tags:myContent = '<div id="test">Hello <span>world!</span></div>';
The result must be:Hello world!
To remove HTML tags, use text() function which returns only the text content and ignores the HTML portion.
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.
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.
var myContent = '<div id="test">Hello <span>world!</span></div>'; alert($(myContent).text());
That results in hello world. Does that answer your question?
http://jsfiddle.net/D2tEf/ for an example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With