Jquery select after all items with certain classes

advertisements

I have a few divs with the same class. The divs are generated dynamically, so I don't always know the exact number of these divs.

I want to place another div after the last div.

<div class="someclassname">content here</div>
<div class="someclassname">content here</div>
<div class="someclassname">content here</div>

When I do this:

$('.someclassname').after('place another div here');

It places it after each one. Is there a way to select the last div with .someclassname?


Use jQuery's last selector like so:

$('.someclassname:last').after('place another div here');

If you want to select the last div with someclassname, and no other element type, then use this instead:

$('div.someclassname:last').after('place another div here');