Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all HTMLtags in a string (with the jquery text() function)

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!

like image 730
Peter Avatar asked Oct 25 '11 13:10

Peter


People also ask

How to remove HTML tags from text in jQuery?

To remove HTML tags, use text() function which returns only the text content and ignores the HTML portion.

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.

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

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

like image 122
Ross Dargan Avatar answered Oct 13 '22 17:10

Ross Dargan