我将使用什么 jQuery 语法来查找父标签(及其所有子标签)中的所有第一代 UL 标签
给定以下 HTML,如何选择所有第一代 UL 标签,以便最终得到以下元素:company、subnav_1 - subnav_4、enginTool、prodSup、qualRel 和 lit,但这些元素内没有 UL ?
<div id="col1">
<h2></h2>
<ul id="company"></ul>
<div id="nav">
<div id="navcordion">
<h2></h2>
<div>
<ul id="subnav_1">
<li>
<ul></ul>
</li>
</ul>
</div>
<h2></h2>
<div>
<ul id="subnav_2">
<li>
<ul></ul>
</li>
</ul>
</div>
<h2></h2>
<div>
<ul id="subnav_3">
<li>
<ul></ul>
</li>
</ul>
</div>
<h2></h2>
<div>
<ul id="subnav_4"></ul>
</div>
</div>
<div class="clear"></div>
</div>
<h2></h2>
<h2></h2>
<ul id="enginTool"></ul>
<h2></h2>
<ul id="prodSup"></ul>
<h2></h2>
<ul id="qualRel"></ul>
<h2></h2>
<h2></h2>
<h2></h2>
<ul id="lit"></ul>
<h2></h2>
</div>
我尝试过 #col1>ul
、#col1 ul:first
和 #col1 ul:nth-child(1)
,但都没有给出我所追求的所有元素。
Given the following HTML, how can I select all of the 1st-generation UL tags such that I end up with the following elements: company, subnav_1 - subnav_4, enginTool, prodSup, qualRel and lit, but none of the ULs inside of those elements?
<div id="col1">
<h2></h2>
<ul id="company"></ul>
<div id="nav">
<div id="navcordion">
<h2></h2>
<div>
<ul id="subnav_1">
<li>
<ul></ul>
</li>
</ul>
</div>
<h2></h2>
<div>
<ul id="subnav_2">
<li>
<ul></ul>
</li>
</ul>
</div>
<h2></h2>
<div>
<ul id="subnav_3">
<li>
<ul></ul>
</li>
</ul>
</div>
<h2></h2>
<div>
<ul id="subnav_4"></ul>
</div>
</div>
<div class="clear"></div>
</div>
<h2></h2>
<h2></h2>
<ul id="enginTool"></ul>
<h2></h2>
<ul id="prodSup"></ul>
<h2></h2>
<ul id="qualRel"></ul>
<h2></h2>
<h2></h2>
<h2></h2>
<ul id="lit"></ul>
<h2></h2>
</div>
I've tried #col1>ul
, #col1 ul:first
and #col1 ul:nth-child(1)
, but neither gives me all of the elements I'm after.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于
只存在于
或
中,这行得通吗?仅选择
的子级
。
使用 jQuery,您应该能够通过将
#col1
的父级作为$()
的第二个参数传递来进行过滤,这样您就不会意外选择其他列表。Since the
<ul>
s are only either in<li>
s or<div>
s, would this work? Only selects<ul>
s that are children of<div>
s.Using jQuery you should be able to filter by passing in the parent of
#col1
as the second argument to$()
so you don't accidentally select other lists.