Introduction to jQuery
JQuery Syntax
JQuery Effects
JQuery HTML
JQuery Traversing
In jQuery, the simplest filtering methods first()
, last()
, and eq()
are used to target elements based on their position within a set of matched elements.
Additional methods like filter()
and not()
help you refine your selection by including only elements that meet or exclude those that don’t meet specific conditions.
The .first()
method in jQuery is used to select the first element from a group of matched elements.
The following example selects the first <div>
element:
Try it yourself
The .last()
method in jQuery is used to select the last element from a set of matched elements.
The following example selects the last <div>
element:
Try it yourself
The .eq()
method in jQuery is used to select a specific element based on its index position in a set of matched elements.
The index numbers start at 0, so the first element will have the index number 0 and not 1. The following example selects the second <p>
element (index number 1):
Try it yourself
The .filter()
method in jQuery is used to narrow down a set of matched elements by keeping only those that match a specified selector, function, or criteria.
The following example returns all <p>
elements with class name "intro":
Try it yourself
The .not()
method in jQuery is used to remove elements from a set of matched elements that match a specific selector or condition.
Tip: The not()
method is the opposite of filter()
.
The following example returns all <p>
elements that do not have class name "intro":
Try it yourself