Reputation: 32986
Let's say I have the following.
<div class="foo">
<div>
some text
<div class="bar">
</div>
</div>
</div>
<div class="foo">
<div>
some text
<div class="bar">
some text
</div>
</div>
</div>
I want return all the divs of class "foo" that have "some text" inside the div class "bar." So the second would be returned, but not the second. How can I do that?
Upvotes: 0
Views: 61
Reputation: 8198
This will do it
$('.foo:has(.bar:not(:empty))')
Make sure there are no characters inside the .bar, even spaces or newlines.
Upvotes: 1
Reputation: 21034
Try this
$("div.bar:contains('some text')").parents(".foo")
Upvotes: 2