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 pla开发者_如何学JAVAces 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');
$('.someclassname:last').after('place another div here');
精彩评论