English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
jQuery allows us to 'traverse' or traverse the HTML elements that make up the page. First, we make an initial selection, and then we traverse the DOM relative to that selection. While traversing the DOM, we are changing the original selection.
jQuery provides a variety of methods to allow us to traverse the DOM.
The largest category of traversal methods is tree traversal.
The following table lists all filtering methods that can be used to filter out various elements from a list of DOM elements:
Method | Description |
---|---|
eq() | Returns the element with the specific index number of the selected elements |
filter() | Reduces the set of matching elements to elements that match the selector or pass the functional test |
first() | Returns the first element of the selected element |
has() | Returns all elements that contain one or more elements |
is() | According to the selector/element/ The jQuery object checks the set of matched elements, and if at least one of these elements matches the given parameter, it returns true |
last() | Returns the last element of the selected element |
map() | Passes each element in the current matching set to a function, producing a new jQuery object containing the returned values |
not() | Returns elements that do not meet specific conditions |
slice() | Reduces the set of matching elements to a subset specified by a series of indices |
The following table lists all tree traversal methods used to traverse the DOM:
Method | Description |
---|---|
children() | Returns all direct children of the selected element |
closest() | Returns the first ancestor of the selected element |
each() | Executes a function for each matching element |
find() | Returns the descendant elements of the selected element |
next() | Returns the next sibling element of the selected element |
nextAll() | Returns all next sibling elements of the selected element |
nextUntil() | Returns all next sibling elements between the two given parameters |
offsetParent() | Return the first located parent element |
parent() | Return the direct parent element of the selected element |
parents() | Return all ancestor elements of the selected element |
parentsUntil() | Return all ancestor elements between two given parameters |
prev() | Return the previous sibling element of the selected element |
prevAll() | Return all preceding sibling elements of the selected element |
prevUntil() | Return all preceding sibling elements between two given parameters |
siblings() | Return all sibling elements of the selected element |
The following table lists all other traversal methods:
Method | Description |
---|---|
add() | Add elements to the matched element set |
addBack() | Add the previous set of elements to the current set |
andSelf() | Version1.8Deprecated in Alias of addBack() |
contents() | Return all direct children of the selected element (including text and comment nodes) |
end() | End the latest filter operation in the current chain and return the matched element set to its previous state |