jQuery: DOM Traversing Methods
jQuery provides a set of methods to traverse and manipulate the DOM efficiently. These methods allow you to navigate through the elements of an HTML document, making it easier to work with complex structures.
Key Methods and Descriptions
Method | Description |
---|---|
add() |
Creates a single jQuery object for all added elements, making it easy to manipulate them simultaneously. |
addBack() |
Creates a single jQuery object for the set of selected elements by selector. |
children() |
Gets all the child elements of the selected element(s). |
closest() |
Traverses up through its ancestors in the DOM tree until it finds the first matched element(s) specified by a selector. |
contents() |
Gets children of all the selected element(s), including text and comment nodes. |
each() |
Iterates over specified elements and executes a specified callback function for each element. |
end() |
Ends the most recent filtering operation in the current chain and returns the set of matched elements to its previous state. |
eq() |
Returns element(s) at the specified index from the selected element (returned from selector). |
filter() |
Reduces the set of matched elements to those that match the selector or pass the function's test. |
find() |
Gets all the specified child elements of each selected element(s). |
first() |
Gets the first occurrence of the specified element. |
has() |
Reduces the set of matched elements to those that have a descendant that matches the selector or DOM element. |
is() |
Checks the current matched set of elements against a selector, element, or jQuery object and returns true if at least one of these elements matches the given arguments. |
last() |
Returns the last element that matched the specified selector. |
map() |
Passes each element in the current matched set through a function, producing a new jQuery object containing the return values. |
next() |
Gets the immediately following sibling of the selected element(s). |
nextAll() |
Gets all following siblings of the selected element(s). |
nextUntil() |
Gets all next sibling elements between two given arguments. |
not() |
Selects elements that do not match the specified selector in the not() method. |
offsetParent() |
Selects the closest ancestor element whose left and top coordinates are closest to matched elements by selector. |
parent() |
Gets the parent of the specified element(s). |
parents() |
Selects all ancestor elements of the matched element(s) by a selector. |
parentsUntil() |
Selects all ancestor elements of the matched element(s), up to but not including the element specified in parentsUntil() . |
prev() |
Selects the immediately preceding sibling of the specified element. |
prevAll() |
Selects all preceding siblings of each matched element, optionally filtered by a selector. |
prevUntil() |
Selects all preceding siblings of each matched element up to but not including matched elements by the selector parameter. |
siblings() |
Gets the siblings of each specified element(s), optionally filtered by a selector. |
slice() |
Selects elements by further filtering elements by specifying a selector parameter. |