jQuery - DOM Traversing

jQuery is a very powerful tool that provides many DOM traversal methods to help us select elements in a document both randomly and sequentially. Most DOM traversals do not modify the jQuery object and are used to filter elements from a document based on specified conditions.
This will give the following result −
-
Each list has its own index above it and can be found directly using the eq(index) method, as shown in the example below.
-
Each child element starts its index at zero, so the list element 2 can be accessed with $("li"). Eq(1) and so on.
Each list has its own index above it and can be found directly using the eq(index) method, as shown in the example below.
Each child element starts its index at zero, so the list element 2 can be accessed with $("li"). Eq(1) and so on.
Item filtering
The filter(selector) method can be used to filter out all elements from a set of matching elements that do not match the specified selectors. A selector can be written using any selector syntax.
Finding child elements
The find(selector) method can be used to locate all descendant elements of elements of a particular type. A selector can be written using any selector syntax.
DOM JOM Filter Methods
The following table lists useful methods that can be used to filter various elements from a list of DOM elements.
Sr.No. | Method and Description |
---|---|
one | eq (index)
Reduce the set of eligible elements to a single element. |
2 | filter (selector)
Removes all elements from the set of matched elements that do not match the specified selectors. |
3 | filter (fn)
Removes all elements from the set of matched elements that do not match the specified function. |
4 | yes (selector)
Tests the current selection against an expression and returns true if at least one selection element matches the given selector. |
five | card (callback)
Translate the set of elements in the jQuery object to another set of values ​​in the jQuery array (which may or may not contain elements). |
6 | no (selector)
Removes elements matching the specified selector from the set of matched elements. |
7 | slice(start, [end])
Selects a subset of matching elements. |
Reduce the set of eligible elements to a single element.
Removes all elements from the set of matched elements that do not match the specified selectors.
Removes all elements from the set of matched elements that do not match the specified function.
Tests the current selection against an expression and returns true if at least one selection element matches the given selector.
Translate the set of elements in the jQuery object to another set of values ​​in the jQuery array (which may or may not contain elements).
Removes elements matching the specified selector from the set of matched elements.
Selects a subset of matching elements.
jQuery DOM traversal methods
The following table lists other useful methods that you can use to find various elements in the DOM.
Adds more elements matching the given selector to the set of matched elements.
Add the previous selection to the current one.
Get an element set containing all the unique immediate children of each matching element set.
Get the set of elements that contains the nearest parent element that matches the specified selector, including the start element.
Find all child nodes within matching elements (including text nodes) or the content document if the element is an iframe.
Revert the most recent "destructive" operation, changing the set of matched elements back to their previous state.
Searches for descendant elements that match the specified selectors.
Get an item set containing the unique nearest siblings of each of the given item set.
Find all siblings after the current element.
Returns a jQuery collection with the positioned parent of the first matched element.
Get the direct parent element. If called on a set of elements, parent returns the set of their unique direct parent elements.
Get a set of elements containing the unique ancestors of the corresponding set of elements (other than the root element).
Get a set of elements containing the unique previous siblings of each of the matched set of elements.
Find all siblings before the current element.
Get an item set containing all the unique siblings of each of the matching item set.