5

Please see the following html

<div class="slick-track">
  <div class="marg first slide-active">1</div>
  <div class="marg second">2</div>
  <div class="marg third">3</div>
  <div class="marg fourth">4</div>
  <div class="marg fifth">5</div>
  <div class="marg sixth">6</div>
  <div class="marg seventh">7</div>
</div>      

Here I want to select slide-active and 2nd marg class after slide-active . How I can select this?

For example:

If slide-active is coming with .first class , then I have to select .third.

If slide-active is coming with .second , then I have to select .fourth.

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Abilash Erikson
  • 341
  • 4
  • 26
  • 55

1 Answers1

8

You can use sibling selector to select it.

.slide-active + .marg + .marg

Snippet to highlight the selected one when active.

.slide-active + .marg + .marg {background: #ccf;}
<div class="slick-track">
  <div class="marg first slide-active">1</div>
  <div class="marg second">2</div>
  <div class="marg third">3</div>
  <div class="marg fourth">4</div>
  <div class="marg fifth">5</div>
  <div class="marg sixth">6</div>
  <div class="marg seventh">7</div>
</div>

When the class is in another one:

.slide-active + .marg + .marg {background: #ccf;}
<div class="slick-track">
  <div class="marg first">1</div>
  <div class="marg second slide-active">2</div>
  <div class="marg third">3</div>
  <div class="marg fourth">4</div>
  <div class="marg fifth">5</div>
  <div class="marg sixth">6</div>
  <div class="marg seventh">7</div>
</div>

Note: This will not work when you are in the last or last but one slide.

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252