Pick items: first, last, eq, filter

Narrow down a set of elements.

jQuery · Pick items: first, last, eq, filterBeginner
const $items = $('#list li');

$items.first().addClass('first');
$items.last().addClass('last');
$items.eq(1).addClass('second');          // zero-based
$items.filter('.done').hide();            // keep only those matching
$items.not('.done').css('font-weight', 'bold');
$items.filter(function () { return $(this).text().length > 3; }).addClass('long');
firstlasteqfilternot