![](/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.