-6

Is there a way to select the TR with 2 TD's in it?

I want to achieve it using pure css. I will use jQuery or javascript, but i want to make sure that this is absolutely not possible using plain CSS before moving to jQuery

For example in jQuery, you have

$("tr").each(function(){
if($(this).children().find("td").length==2){
  $(this).css({some properties});
}
})

Can something similar to this be achieved using CSS?

Vignesh Subramanian
  • 7,161
  • 14
  • 87
  • 150
  • 1
    Please add you code. – Alex Mac Jun 15 '17 at 05:24
  • @Kobi, the question you marked as duplicate is not relative to the topic – KAD Jun 15 '17 at 05:31
  • 2
    duplicate off https://stackoverflow.com/questions/8720931/can-css-detect-the-number-of-children-an-element-has – Elie Nassif Jun 15 '17 at 05:31
  • 1
    @KAD - It certainly is. There are no parent selectors at all (yet). If there were, you would be able to use `nth-child` (or `+`, and/or `:not`) to count children. – Kobi Jun 15 '17 at 05:36
  • @ShyamShingadiya i have added jquery code, looking to achieve similar using plain css – Vignesh Subramanian Jun 15 '17 at 05:40
  • @Kobi, the question you linked asks if you can select a parent based on a child element specifying certain element types. This question asks about an abstract theory to select a parent based on the number of children independent of types – KAD Jun 15 '17 at 05:53
  • @vignesh, I am not sure but this is something can help you. `tr td:nth-child(-n+2){ border:1px solid black; }` – Alex Mac Jun 15 '17 at 06:04
  • 1
    re-opening the questions for votes @ShyamShingadiya thanks, I am actually looking to apply style to TR based on number of TDs. – Vignesh Subramanian Jun 19 '17 at 08:24

1 Answers1

2

You cannot select a parent based on the number of children it has in css, you can only apply styles to nodes based on their siblings. So this is not feasible in your case.

KAD
  • 10,972
  • 4
  • 31
  • 73