Selecting an object at a specific index with jQuery

Bookmark and Share
July 6, 2010 Category: jQuery Tips

As you probably know, the jQuery selector returns all the matched elements as an array. But what if you needed to select only the third element in the returned elements list?
The code below will return only the 3rd element in the returned selected list

// get 3rd item as a jQuery object:
$('div:eq(2)')
 
// get 3rd item as a pure DOM object
$('div')[2];

0 comment so far

Add New Comment




Your Comment