I am sorry for the title, don't know how to describe it better.
I have following structure:
<div id="content">
<ul id="linklist">
<li><a>...</a></li>
<li><a>...</a></li>
<li><a>...</a></li>
<li><a>...</a></li>
</ul>
<a>...</a>
<div> //variable depth of divs
<a>...</a>
</div>
</div>
I want to select all links () beside the third and fourth one in the #linklist.
I've tried some jQuery selectors but i can't find a working one.
$(":not(#linklist li:gt(2) a) a")
does show the third and fourth link too. I think because the li are still exist in the match of "not".
What is the correct selector for the problem?
答案 0 :(得分:1)
我采用不同的方法。
提供您不想选择唯一类名的元素(即.ignore
)
<li><a>...</a></li>
<li><a>...</a></li>
<li><a class="ignore-me">...</a></li>
<li><a class="ignore-me">...</a></li>
然后你可以这样做:
a:not(.ignore-me)
这将更易于维护(即,如果链接位置发生变化),并且同样适用于jQuery和CSS。
希望这有帮助。
答案 1 :(得分:1)
:gt
选择器中的语法有点偏差。 :gt
应位于#linklist a
元素上,索引从零开始,因此应为1
。试试这个:
$('a:not(#linklist a:gt(1))')
答案 2 :(得分:0)
您可以将.not()
方法与要从选择中删除的两个索引一起使用:
$('#linklist').find('a').not(':eq(2)').not(':eq(3)');
答案 3 :(得分:0)
尝试:
$('#linklist li').not('li:nth-child(3)').not('li:nth-child(4)');
或:
$('#linklist li').not('li:gt(1)');
答案 4 :(得分:0)
试试这个:
$('#linklist li').not(":eq(3)").not(":eq(2)")