I have the following HTMl structure, which i cannot change.
<div class="X">
<ul>
<li><a><img></a></li>
<li><a><img></a></li>
<li><a><img></a></li>
<li><a><img></a></li>
<li><a><img></a></li>
<li><a><img></a></li>
<li><a><img></a></li>
<li><a><img></a></li>
<li><a><img></a></li>
<li><a><img></a></li>
</ul>
</div>
The number of li items varies. I would like to select the nth element from the back and modify the img src.
This is what i have so far:
$('div.X').find('img').css('background-color', 'red');
I need some way to loop over the results of the .find and then somehow select the nth last element. I was thinking i should somehow reverse the list so i could just use the nth-child() selector.
I've found various other nth related questions, but i havn't been able to figure out how to nail this.
Any help is much appriciated.