<分区>
<分区>
假设我有这个无序列表:
<ul>
<li class="item"></li>
<li class="item"></li>
<li class="item"></li>
<li class="placeholder"></li>
</ul>
我正在对 .item
进行排序,如果它是列表中的最后一个 .item,它将被移动到其他列表。我会经常使用 :last-child
但是如果那里有一个 .placeholder
元素它不会识别最后一个元素,而是认为由于占位符元素不是最后一个。
我怎样才能让它只选择最后一个 .item
??
最佳答案
在元素元素的对象上使用 :last
选择器或 .last()
方法:
$('.item:last');//will give third li
或
$('.item').last();//will give third li
关于jquery - 选择 :last-child, 但具有特定类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31206628/
相关文章:
jquery .insertAfter - 能够移动元素,但不能将其移回原处
javascript - Chrome DevTools 时间轴 : Frame View appears inconsistent with Records chart
javascript - 从 href 链接链接到特定选项卡
html - JS 树 : Change Icon using CSS not accepting the base64 image code
jquery - 使用 CSS 和 JQuery 绘制垂直线