0

I have a case when the HTML is being generated dynamically using JS.

I want to apply some styles for given code for specific class. The problem is I can't change HTML syntax, because it is an external resource returned into my client app.

In case:

<div class="parent">
   <div class="c1" />
   <div class="c1" />
   <div class="c1" />
   <div class="c1" /> // this one should be selected
</div>

In other case:

<div class="parent">
   <div class="c1" />
   <div class="c1" />
   <div class="c1" />
   <div class="c1" /> // this one should be selected
   <div class="c2" />
</div>

In other words, I want to select the last child within parent block that contains chosen-css-class.

I tried :last-of-type, but it doesn't work for classes. Is it possible to solve this issue using CSS only?

Also tried to find something on Web, but wasn't lucky too much...

Nickon
  • 9,652
  • 12
  • 64
  • 119
  • 1
    You definitely need JS for this. Neither `last-child` nor `last-of-type` would work here. In the second case, the `div` with class `c1` is neither the last child of the parent nor is it the last element of its type within the parent. You can find some information on how it works here - http://stackoverflow.com/questions/18995362/last-child-not-working-as-expected/18995451#18995451 – Harry Aug 24 '15 at 11:49
  • Please, convert your comment into an answer. I will mark it with a green tick. – Nickon Aug 24 '15 at 11:58

0 Answers0