views:

187

answers:

4

i searched the docs and couldnt find it :(

let's say i'm selecting all elements like:

var items = $(".myClass");

it returns eg. 5 items - now how can i grab select eg. the 2nd one? items(2) or items[2] doesnt work ..

+3  A: 

Try this:

items.eq(2) // gets the third element (zero-based index)

Source: http://docs.jquery.com/Traversing/eq#index

GoodEnough
damn that was quick - thanks dude!
Fuxi
+1 Because I always use items.get(2) and I didn't know about this method. Does anyone know the difference?
Andy McCluggage
A: 

arrays are zero based so you need items[1] for the second one

Question Mark
A: 

2nd item would be items[ 1 ] in your case. Also the code you've provided works perfectly for me (with items[ 1 ]).

Ondrej Slinták
A: 

try

var items = $(".myClass"); alert($(items)[1]);

gg