Jquery Traversing Methods

Traversing means "moving through". JQuery provides a variety of methods that allows us to traverse the DOM. Jquery Traversing methods are used to find or select HTML elements based on their relation to other elements. The traverse starts from one selection and move through that selection until you reach the desired elements.

The JQuery traversing methods enable you to easily move up to the ancestor elements, move down to descendant elements and move sideways to sibling elements in the family tree, starting from the current element. This movement is called traversing also known as moving through the DOM. The largest category of traversal methods are tree-traversal. Here is a brief description of all jQuery Traversing methods.

add() :

Adds elements to the existing group of matched elements.

andself() :

The andSelf( ) method adds the previous selection to the current selection.

children() :

The children() method returns all direct children of the selected element.

closest() :

The closest() method returns the first ancestor of the selected element.

contents() :

The contents() method returns all direct children, including text and comment nodes, of the selected element.

end() :

The end() method end the most recent filtering operation in the current chain and return the set of matched elements to its previous state.

find() :

The find() method returns descendant elements of the selected element.

next() :

The next() method returns the next sibling element of the selected element.

nextall() :

The nextAll() method returns all next sibling elements of the selected element.

offsetParent() :

The offsetParent() traverses along the DOM tree and searches through the ancestors of the selected element and construct a new jQuery object wrapped around the closest positioned ancestor.

parent() :

The parent() method returns the direct parent element of the selected element.

prev() :

The prev() method returns the previous sibling element of the selected element.

prevall() :

The prevAll() method returns all previous sibling elements of the selected element.

siblings() :

The siblings() method returns all sibling elements of the selected element.

Ask Questions

Ask Question