![](/img/trans.png)
[英]How can I identify an element with no class/ID and won't always be the same nth child?
[英]How can I get nth child in array of items retrieved by class?
我的brandPagination
有几个<a>
元素
如果我使用这个:
console.log($j('.brandPagination'));
我得到一个包含五个项目的数组。 我要第n个。 所以我尝试了:
console.log($j('.brandPagination:nth-of-type(1)'));
这将输出一个空数组,为什么以及我该怎么办?
您可以使用
$j('.brandPagination:eq(0)');
// or
$j('.brandPagination').eq(0);
请记住, nth-of-type
从1开始,而jQuery的eq
从零开始。
使用last-child选择器来获取之前指定的选择器的最后一项。
试试看
console.log($j('.brandPagination:last-child'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.