<div class="news">
i need this content
<figure class="summary">
i dont need this content
</figure>
</div>
I want to get "i need this content" in class .news but without "i dont need this content" in class .summary
$("div.news").not("figure.summary").text()
I tried this jquery but still gettiing text in figure tag.
alert($("div.news").contents().not("figure.summary").text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="news">
i need this content
<figure class="summary">
i dont need this content
</figure>
</div>
You should use contents() to include textNodes:
$("div.news").contents().not("figure.summary").text()
And if you want to get only textNodes, not filtering out by specific class, type, etc...:
$("div.news").contents().not("div.news *").text()
Learn more about .contents() at: http://api.jquery.com/contents/
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