CSS selector for "foo that contains bar"?
No, what you are looking for would be called a parent selector. CSS has none; they have been proposed multiple times but I know of no existing or forthcoming standard including them. You are correct that you would need to use something like jQuery or use additional class annotations to achieve the effect you want.
Here are some similar questions with similar results:
- Is there a CSS parent selector?
- CSS Parent/Ancestor Selector
- Complex CSS selector for parent of active child
Only thing that comes even close is the :contains
pseudo class in CSS3, but that only selects textual content, not tags or elements, so you're out of luck.
A simpler way to select a parent with specific children in jQuery can be written as (with :has()
):
$('#parent:has(#child)');