views:

28

answers:

2

Is there an array created somewhere of all the objects with a specific class? 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"?

+1  A: 

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.

Matt
Matt, thanks for the answer. I know this is a little off topic to the comment, but what is the difference between DOM HTML Element and jQuery wrapped element?
Albion
A: 

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

Teja Kantamneni
.eq() in jquery is meant for this. not the nth selector
Umair