After selecting a set of elements, you often want to narrow that set — keeping only elements that meet certain criteria. jQuery's filtering methods let you refine selections without writing new, more complex selectors. They are faster and more readable because they operate on an already-retrieved set.
The Filtering Family
jQuery provides a rich set of filtering methods: .filter() to keep matches, .not() to exclude matches, .has() to keep elements that contain a specific descendant, .is() to test the entire set, and index-based filters like .first(), .last(), and .eq().
Selectors vs Filtering Methods
Complex CSS selectors applied to the whole document can be slow on large pages. Building your query in two stages — a broad selector to retrieve a manageable set, then a filtering method to narrow it — is often faster and always more readable.
.filter(selector)— keep only matching elements.not(selector)— exclude matching elements.has(selector)— keep elements with a matching descendant.is(selector)— returns true/false, does not filter.first(),.last(),.eq(n)— index-based selection