-3

I need to change the color of text 5 to red.

This doesn't work. What is the possible resolution to this problem?

Note: This is a small representation of the actual problem. So the placement of children is not fixed, nor their numbers.

#parent>.child:last-of-type {
  color: red;
}
<div id="parent">
  <span class="child">1</span><br>
  <a>2</a><br>
  <span class="child">3</span><br>
  <a>4</a><br>
  <span class="child">5</span><br>
  <span>6</span>
</div>
Himanshu Aggarwal
  • 1,763
  • 1
  • 23
  • 35

1 Answers1

0

Try this one

#parent span:nth-child(9) {
  background: red;
}
<div id="parent">
  <span class="child">1</span><br>
  <a>2</a><br>
  <span class="child">3</span><br>
  <a>4</a><br>
  <span class="child">5</span><br>
  <span>6</span>
</div>
Temani Afif
  • 211,628
  • 17
  • 234
  • 311
Nisha
  • 583
  • 4
  • 7