Skip to the content.

$.fn.parent() / $.fn.parents() / $.fn.parentsUntil()

Walk upwards through the ancestor chain of every item in the collection. Three related methods: a single step (parent), all the way to the document (parents), or stopping at a boundary selector (parentsUntil).

Signatures

parent(selector?: Selector): this;
parents(selector?: Selector): this;
parentsUntil(selector: Selector, filter?: Selector): this;

Parameters

Returns

A new Dabby collection of ancestor elements.

Examples

import $ from "dabbyjs";
import "dabbyjs/traversal/parents/parents";

// The immediate parent
$("a.external").parent();
import $ from "dabbyjs";
import "dabbyjs/traversal/parents/parents";

// Every ancestor that is a section
$(".callout").parents("section");
import $ from "dabbyjs";
import "dabbyjs/traversal/parents/parents";

// Walk up only as far as the article boundary
$(".callout").parentsUntil("article");

See also