Peter Peter - 7 months ago 8
Javascript Question

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!

Answer
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

Comments