tags:

views:

461

answers:

3

How would I make a css selector with that applies style to a table cell that has an input child element?

Edit: This is an exact duplicate of another question.

+2  A: 

According to Wikipedia:

Selectors are unable to ascend

CSS offers no way to select a parent or ancestor of element that satisfies certain criteria. A more advanced selector scheme (such as XPath) would enable more sophisticated stylesheets. However, the major reasons for the CSS Working Group rejecting proposals for parent selectors are related to browser performance and incremental rendering issues.

And for anyone searching SO in future, this might also be referred to as an ancestor selector.

Sam Hasler
+4  A: 

Unfortunately, you can't target parent elements in CSS yet (I believe it will come in CSS3)(see Sam's answer). If you want to do this, you'll either have to a) use javascript or b) add a class name to the td containing the input.

Here is a nice reference of the selectors you can use currently to target children, siblings, types, etc.

tj111
+1  A: 

If you're using jQuery:

$("td input").each(function() { $(this).parent("td").css("style", "value"); });

Plan B