Reputation: 2915
<div id="main">
<div class="1"></div>
<div class="2"></div>
<div class="2"></div>
<div class="3"></div>
<div class="3"></div>
<div class="4"></div>
</div>
How we can write a selector using :last-child
in jquery to find out the last div with class 3
?
Upvotes: 3
Views: 433
Reputation: 140234
Try this selector... though your classes shouldn't be just numbers. They should start with a normal character.
$("#main .3:last")
FYI, :last-child
checks if the target is last child of its parent. None of the elements with class .3
are the last child of their parent.
Upvotes: 12