jQuery traversal

jQuery traversal is to find and select html elements based on their relationship to other elements.

With jQuery traversal, you can start from the selected element and move up the DOM tree (ancestors), down (descendants), and horizontally (sibs).

jQuery Traversal: Ancestors

Move up the DOM tree to find the ancestor of the element.

1. parent() : Returns the immediate parent element of the selected element.

2. parents() : Returns all ancestors of the selected element, all the way up to the root element of the document; parameters can be used to filter the search for ancestors.

3. parentsUntil() : Returns all ancestor elements between two given elements.

jQuery Traversal: Descendants

Traverse down the DOM tree to find the descendants of the element.

1. children() : Returns all direct children of the selected element; parameters can be used to filter the search for child elements.

2. find() : Returns the descendant elements of the selected element, all the way down to the last descendant.

jQuery Traversal: Siblings

1. siblings() : Returns all sibling elements of the selected element; parameters can be used to filter the search for sibling elements.

2. next() : Returns the next sibling element of the selected element. (traversing the elements after the given element)

3. nextAll() : Returns the next and subsequent sibling elements of the selected element.

4. nextUntil() : Returns all sibling elements between the two given parameters.

5. prev() : Returns the previous sibling element of the selected element. (traverse the elements before the given element)

6. prevAll() : Returns the previous and above all sibling elements of the selected element.

7. prevUntil() : Returns all sibling elements between the two given arguments.

jQuery Traversal: Filtering

Select a specific element from a set of elements.

1. first() : Returns the first element of the selected element.

2. last() : Returns the last element of the selected element.

3. eq() : Returns the element with the specified index number among the selected elements; the index number starts from 0, and the index number of the first element is 0 not 1.

4. filter() : Returns elements that match the specified criteria.

5. not() : Returns all elements that do not match the criteria.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324695997&siteId=291194637