tags:

views:

410

answers:

3

hi , i want to grab text inside a div element like this :

<div class='someclass'> 
<blockquote>some text ! </blockquote>
another text goes here . 
</div>

so i get all text with jQuery like this: var qtext = $('.someclass').text();

but i don't want <blockquote>some text ! </blockquote> i just need the text inside div element . how can i filter that ?

tanks guys .

+1  A: 

See "strip HTML tags": http://devkick.com/blog/parsing-strings-with-jquery/

James Skidmore
Yeah , that's perfect but it's only clear html tags . i need to clear html tag with the text inside of it .
mehdi
+1  A: 

This a workaround :

var div = $('.someclass').clone();
div = div.find('blockquote').remove().end();
alert(div.text());
Marwan Aouida
Perfect,Tank You !
mehdi
A: 

What you want is only to select the TextNodes:

var textNodes =   $('.someclass').contents()
                                 .filter(function() {
                                   return this.nodeType ==  Node.TEXT_NODE;
                                 });

That will give you an array of TextNodes, you could then extract the actual text content of all the nodes to an array:

var textContents = $.map(textNodes, function(n){return n.textContent;});
CMS