I have a few <a>
elements with the class brandPagination
If I use this:
console.log($j('.brandPagination'));
I get an array with five items in it. I want the nth one. So I tried:
console.log($j('.brandPagination:nth-of-type(1)'));
This outputs an empty array, why and what can I do about it?
You can either use
$j('.brandPagination:eq(0)');
// or
$j('.brandPagination').eq(0);
Keep in mind nth-of-type
starts in 1, and jQuery's eq
is zero based.
Use the last-child selector to fetch the last item of the selector specified before.
Try this out,
console.log($j('.brandPagination:last-child'));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.