1

With the following template how can I get just get "Obtain this text"

<h1 class="classA classB"> Obtain this text <span class="unwanted"> unwanted text </span> </h1> 

I tried $('.classA.classB:not(.unwanted)') but I get the whole thing back without unwanted.

2 Answers 2

2
$("#foo") .clone() //clone the element .children() //select all the children .remove() //remove all the children .end() //again go back to selected element .text(); //get the text of element 

.remove() accepts a selector , so you can do something like .remove('.unwanted')

sourse http://viralpatel.net/blogs/jquery-get-text-element-without-child-element/

demo

http://viralpatel.net/blogs/demo/jquery/get-text-without-child-element/

please google before asking

Sign up to request clarification or add additional context in comments.

Comments

2

jsFiddle
Clone it, drop the kids, get the text:

$('.classA').clone().find('.unwanted').remove().end().text(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.