开发者

jQuery create an array of objects with a specific class

Is there an array created somewhere of all the objects with a specific c开发者_运维知识库lass? I want to find the sixth div with class="clCategory". Is there something like:

$('.clCategory:sixth').css(...);

or

$('.clCategory')[6].css(...);

Or do I have to create the array at the same time I programmatically create each of the DIVs with class="clCategory"?


You're looking for eq(x)

It's 0-based, so the 6th would actually be #5

E.g.:

$('.clCategory:eq(5)')

You can also query for $('.clCategory') and access it at [5] or even .get(5). The difference with either is that you would be getting the DOM HTMLElement, not the jQuery wrapped element as in my previous example.


You have to use nth child selector. See this related post.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜