簡體   English   中英

我如何在按班級檢索的項目數組中獲得第n個孩子?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM