The first(), last(), eq(), filter() and not() Methods
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() andnot() help you refine your selection by including only elements that meet or exclude those that don’t meet specific conditions.
jQuery first() Method
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:
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):
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":
We use cookies and similar technologies to enhance your browsing experience, serve personalized content and advertisements, and analyze our traffic.
By clicking "Accept All", you consent to our use of cookies and the processing of your personal data for these purposes.
You can manage your preferences or learn more in our
Privacy Policy and
Cookie Policy.