-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,803
  • 2
  • 24
  • 36

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
  • 245,468
  • 26
  • 309
  • 415
Nisha
  • 623
  • 5
  • 7