【发布时间】:2012-05-24 16:47:39
【问题描述】:
我有一个看起来像这样的表格:
<ul id="services">
<li class="service"><label><input type="checkbox">A single option</label>
</li>
<li class="service"><label><input type="checkbox">Another single option</label>
<ul>
<li>
<select>
</select>
additional options</li>
</ul>
</li>
<li class="service"><label>
<select>
</select>
A multiple option</label>
<ul>
<li><label><input type="checkbox"> with another option </label>
<select>
</select>
</li>
</ul>
</li>
<li class="service"><label>
<select>
</select>
Another multiple option</label>
<ul>
<li><label><input type="checkbox"> with another option </label>
<select>
</select>
</li>
<li>
<select>
</select>
additional options</li>
</ul>
</li>
我正在尝试使用以下方法仅选择<li>s 的第一级中的<label>s 和“服务”类:
$(".service label:first-child").css("background", "yellow");
但它似乎是递归的,并且正在选择嵌套<ul>s 的第一个孩子。
我在这里做错了什么?如何只选择具有“服务”类的<li>s 的第一级中的<label>s?
【问题讨论】:
标签: jquery jquery-selectors css-selectors