Narrowing the range of search elements
The three most basic filtering methods are: First (), Last (), and EQ (), which allow you to select a specific element based on its position within a set of elements.
Other filtering methods, such as filter () and not (), allow you to select elements that match or do not match a specified criterion.
JQuery First () method
The first () method returns the initial element of the selected element.
The following example selects the first <p> element inside the first <div> element:
Instance $ (document). Ready (function () {
$ ("div p"). First ();
});
Try it?
JQuery Last () method
The last () method returns the final element of the selected element.
The following example selects the last <p> element in the last <div> element:
Instance $ (document). Ready (function () {
$ ("div p"). Last ();
});
Try it?
JQuery eq () method
The EQ () method returns the element with the specified index number in the selected element.
The index number starts at 0, so the first element's index number is 0 instead of 1. The following example selects a second <p> element (index number 1):
Instance $ (document). Ready (function () {
$ ("P"). EQ (1);
});
Try it?
JQuery Filter () method
The filter () method allows you to specify a standard. Elements that do not match this standard are removed from the collection, and the matching elements are returned.
The following example returns all the <p> elements with the class name "Intro":
Instance $ (document). Ready (function () {
$ ("P"). Filter (". Intro");
});
Try it?
JQuery not () method
The Not () method returns all elements that do not match the criteria.
Tip: The Not () method is the opposite of filter ().
The following example returns all the <p> elements without the class name "Intro":
Instance $ (document). Ready (function () {
$ ("P"). Not (". Intro");
});
Try it?
JQuery Traversal – Filtering