tags:

views:

287

answers:

5

Is there a way to make a CSS Selector that matches the following?

All OBJECT elements
  which have a PARAM element inside of them

The selector

OBJECT PARAM

doesn't work, as it matches the PARAM, not the OBJECT. I'd like to apply { display:none } to the objects; it's useless to apply that to the PARAMs.

(I'm aware I could pull this off with jQuery -- $("object param").closest("object") -- but I'm trying to create CSS rules on a page.)

+3  A: 

No, to the best of my knowledge this is not possible with pure CSS. You will need to use jQuery (or a similar solution) to achieve this result.

Jonathan Sampson
+2  A: 

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:

Michael Greene
+1  A: 

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:

$('#parent:has(#child)');
Tatu Ulmanen
Thanks -- but how is that different from $("#parent #child")?
Michael Gundlach
`$("#parent #child")` selects all #child elements that are children of #parent. `$('#parent:has(#child)')` selects all #parent elements that have #child as children.
Tatu Ulmanen
+1  A: 

Is there any way you could programatically apply a class to the object? then do object.hasparams

Jeepstone
Thanks, but I need to do this before the objects even exist; otherwise they will flash up momentarily before being hidden.
Michael Gundlach
A: 

Maybe you could make something work with Conditional selectors:

http://www.hunlock.com/blogs/Attach_icons_to_anything_with_CSS

I know it's a leap, but worth a look. Hope this helps.

tahdhaze09