This article brings you a summary of the Query traversal method. Friends who need it can refer to it. I hope it can help everyone. Let’s take a look with the editor below.
Function Description
.add() Adds elements to the set of matching elements.
.andSelf() Adds the previous set of elements in the stack to the current set.
.children() Gets all child elements of each element in the matching element set.
.closest() starts from the element itself, matches the upper elements step by step, and returns the first matched ancestor element.
.contents() Gets the child elements of each element in the set of matching elements, including text and comment nodes.
.each() iterates over a jQuery object, executing a function for each matching element.
.end() Ends the latest filtering operation in the current chain and returns the set of matching elements to the previous state.
.eq() Reduces the set of matching elements to the new element at the specified index.
.filter() Reduces the set of matching elements to new elements matching the selector or matching function return value.
.find() Gets the descendants of each element in the current matching element set, filtered by the selector.
.first() Reduces the set of matching elements to the first element in the set.
.has() Reduces the set of matching elements to a set containing the descendants of the specific element.
.is() Checks the current set of matching elements based on the selector and returns true if there is at least one matching element.
.last() Reduces the set of matching elements to the last element in the set.
.map() passes each element in the current matching set to the function and generates a new jQuery object containing the return value.
.next() Gets the immediately adjacent sibling elements of each element in the matching element set.
.nextAll() Gets all sibling elements after each element in the matching element set, filtered by the selector (optional).
.nextUntil() Gets all sibling elements after each element until an element matching the selector is encountered.
.not() Remove elements from the set of matching elements.
.offsetParent() Gets the first parent element for positioning.
.parent() Gets the parent element of each element in the current matching element set, filtered by the selector (optional).
.parents() Gets the ancestor elements of each element in the current matching element set, filtered by the selector (optional).
.parentsUntil() Gets the ancestor elements of each element in the current set of matching elements until an element matching the selector is encountered.
.prev() Gets the immediately preceding sibling element of each element in the matching element set, filtered by the selector (optional).
.prevAll() Gets all sibling elements before each element in the matching element set, filtered by the selector (optional).
.prevUntil() Gets all sibling elements before each element until an element matching the selector is encountered.
.siblings() Gets the sibling elements of all elements in the matching element set, filtered by the selector (optional).
.slice() Reduces the set of matching elements to a subset of the specified range.
Related recommendations:
Several ways to traverse collections
4 ways to traverse Map objects in Java
The above is the detailed content of Summary of jQuery traversal methods. For more information, please follow other related articles on the PHP Chinese website!