Jquery 选择器 Class>子项>子项
Jquery Selector Class>Child>Child
因此,我不想指定 id 或 class,而是想通过使用子元素和 class 名称的组合来磨练特定元素。
那么我如何使用 jquery 选择器指定我想要任何中心元素的 first/last 子元素,该元素是 div 和 class 的子元素名称 == 示例?
<div class="example">
<center>
<a> <!--I want to be able to select this element -->
<a> <!--or this one -->
</center>
</div>
您需要首先执行此操作:
$('div.example>center>*:first-child');
这是最后一个:
$('div.example>center>*:last-child');
您可以在 jsfiddle.net 上查看工作示例。
只要确定你真的想要 Child and not Descendants。
因此,我不想指定 id 或 class,而是想通过使用子元素和 class 名称的组合来磨练特定元素。
那么我如何使用 jquery 选择器指定我想要任何中心元素的 first/last 子元素,该元素是 div 和 class 的子元素名称 == 示例?
<div class="example">
<center>
<a> <!--I want to be able to select this element -->
<a> <!--or this one -->
</center>
</div>
您需要首先执行此操作:
$('div.example>center>*:first-child');
这是最后一个:
$('div.example>center>*:last-child');
您可以在 jsfiddle.net 上查看工作示例。
只要确定你真的想要 Child and not Descendants。