选择所有li但不是孩子 [英] Select all li's but not children
本文介绍了选择所有li但不是孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码:
$li = $("li", this)
在我的代码中选择所有 li
。这工作正常,但我想要 $ li
来排除子菜单中的 li
。
Which is selecting all of the li
's in my code. This works fine however I want $li
to exclude the li
's that are within a submenu.
<ul id="navigation">
<li><a href="#">blah 1</a></li>
<ul id="subnav">
<li><a href="#">sub 1</a></li>
<li><a href="#">sub 2</a></li>
<li><a href="#">sub 3</a></li>
</ul>
</li>
<li><a href="#">blah 2</a></li>
<li><a href="#">blah 3</a></li>
<li><a href="#">blah 4</a></li>
<li><a href="#">blah 5</a></li>
</ul>
所以 $ li
只会参考blah的不是sub的。
So $li
would only reference the blah's not the sub's.
我认为它是这样的:
$li = $("li", this).parents()
但这不做我想要的是什么。
But this doesn't do what I want.
推荐答案
只需使用子选择器>
:
$("#navigation > li")
这篇关于选择所有li但不是孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文