如何删除特定元素 (p#heading) 之后的最后三个项目(具有相同的类)?
<p id="heading">HEADING</p>
<p class="txt"></p>
<p class="txt"></p>
<p class="txt"></p>
<p class="txt"></p>
<p class="txt"></p>
<p class="txt"></p>
谢谢了!
最佳答案
这匹配 .txt
元素 after p#heading
和 slices选择匹配集中的最后三个。
$matchedElements = $('p#heading').nextAll('.txt').slice(-3);
关于jQuery 删除特定元素后的最后三个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12760500/