Easy Tutorial
❮ Misc Inarray Html Empty ❯

jQuery parentsUntil() Method

jQuery Traversing 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 from the parent upwards until it reaches the document root, all the way to the specified element.

Note: If both parameters are empty, this 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 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 Traversing Methods

❮ Misc Inarray Html Empty ❯