帮助JQuery选择器:not(:last)
我正在尝试选择除了最后一颗子弹之外的所有子弹但是我做错了。
这是我的HTML
- Text
- Text
- Text
- Text
- Text
- Text
- Text
- Text
- Text
- Text
- Text
- Text
- Text
- Text
- Text
而我的jQuery:
jQuery('ul li:not(:last)').append(" | ");
它正在为每个子弹添加管道但是……
因为你的html包含多个无序列表,所以$('ul li')
将在所有
选择每个
。 :last
然后选择该列表中的最后一个元素。 使用:last-child
,它获取每个
的最后一个
。
$('ul li:not(:last-child)').append(' | ');