When I use the :contains
selector, it returns all elements (including parents/ancestors) matching the selector. How can I just return the child-most/deepest element that matches?
Example:
<div>
<div>some text</div>
<div>more text</div>
<div>
even more text
<div>Copyright 2013</div> <!-- I only want this div -->
</div>
</div>
.
console.log($(':contains(Copyright)'));
JSFiddle: http://jsfiddle.net/rQ7qP/
I don't know anything about the containing page, i.e. It could be in any element type, or with any class/id attribute. Nothing can be assumed.
Try
console.log($(':contains(Copyright):not(:has(*))'));
Demo: Fiddle
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