jQuery和x27之间的区别是什么;s空间与>;选择器?
和选择器之间有什么区别?而且可能是相关的,我如何才能寻找其他事物的直接子对象,而不降低后代线jQuery和x27之间的区别是什么;s空间与>;选择器?,jquery,css,jquery-selectors,css-selectors,Jquery,Css,Jquery Selectors,Css Selectors,和选择器之间有什么区别?而且可能是相关的,我如何才能寻找其他事物的直接子对象,而不降低后代线 <ul> <li>Item 1</li> <li>Item 2 <ul> <li>Item 2.1</li> <li>Item 2.2</li> </ul> </li> <li>Item 3</li&
<ul>
<li>Item 1</li>
<li>Item 2
<ul>
<li>Item 2.1</li>
<li>Item 2.2</li>
</ul>
</li>
<li>Item 3</li>
</ul>
将类别“blah”添加到1 2和3,而:
$("ul li").addClass("blah");
将类“blah”添加到每个列表元素
我不确定你指的是
表示“的直接子节点”:仅选择作为直接子节点的节点
而空格的意思是“任何子代”:可以选择直接子代和这些子代的子代
我敢打赌jQuery使用相同的约定。如前所述,空格将选择任何子代,而
将只选择直接子代。如果只想选择孙子或曾孙,则可以使用以下选项:
#foo > * > * > .bar
(所有类为“bar”的元素都是id为“foo”的元素的曾孙元素)看看这个
$(".testit > a") //match the first <a> tag below
$(".testit a") // matches all <a> tag below
<p class="testit">
<a href="#">All the rules will match this</a>
<span>
<a href="#">second rule can only select this</a>
</span>
</p>
$(“.testit>a”)//匹配第一个
ul>li是否将所有这些设置都设置为“废话”?因为您的子列表在ul中也有li子列表。>表示直系子列表,而不是孙子或更多。ul>li也与嵌套列表匹配。您应该更新示例,使内部的ul
作为ol
,因为您当前的代码不会像您描述的那样工作(尽管技术上正确)。
$(".testit > a") //match the first <a> tag below
$(".testit a") // matches all <a> tag below
<p class="testit">
<a href="#">All the rules will match this</a>
<span>
<a href="#">second rule can only select this</a>
</span>
</p>