Position filter in jQuery

jQuery allows you to filter the elements selected based on their position in the collection. For example:

$('.article:eq(2)');
Selects the third element with the class article. Elements in a collection are numbered starting with 0.
$('.article:gt(1)');
From the collection of all elements with the class article, select all elements following the second one.
$('.article:lt(3)');
From the collection of all elements with the class article, select up to the first three.
$('.article:first');
Selects the first element with the class article
$('.article:last');
Selects the last element with the class article
$('.article:odd');
Selects the odd elements out of all the elements with the class article (zero-based index: 1,3,5,etc)
$('.article:even');
Selects the even elements out of all the elements with the class article (zero-based index: 0,2,4,etc)

No comments:

Post a Comment