Easy Tutorial
❮ Sel Gt Html Wrap ❯

jQuery parentsUntil() Method

jQuery Traversal Methods

Example

Returns all ancestor elements between a <span> and a <div>:

Result:


Definition and Usage

The parentsUntil() method returns all ancestor elements between the selector and stop.

Ancestors are the parent, grandparent, great-grandparent, and so on.

DOM Tree: This method traverses the ancestors of the DOM elements upwards from the parent, all the way to the document root, until it reaches the specified element.

Note: If both parameters are empty, the method will return all ancestor elements (same as the parents() method).

Related Methods:


Syntax

Parameter Description
stop Optional. A selector expression, element, or jQuery object indicating where to stop matching ancestor elements.
filter Optional. A selector expression that narrows down the scope of the search for ancestor elements between the selector and stop. <br> <br> Note: To return multiple ancestor elements, separate each expression with a comma.

More Examples

Narrow Down the Search

Return Multiple Ancestor Elements

DOM

Filter Search Using DOM Elements and Selector Expressions


jQuery Traversal Methods

❮ Sel Gt Html Wrap ❯