开发者

jquery select after all elements with certain class

开发者 https://www.devze.com 2023-03-06 04:04 出处:网络
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 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');
0

精彩评论

暂无评论...
验证码 换一张
取 消