Skip to the content.

$.fn.next() / $.fn.nextAll() / $.fn.nextUntil() / $.fn.prev() / $.fn.prevAll() / $.fn.prevUntil()

Walk forwards or backwards through the immediate sibling chain of every item in the collection. The six methods share the same shape, differing only in direction (next vs prev) and how far they walk (one step, all the way, or until a boundary).

Signatures

next(selector?: Selector): this;
nextAll(selector?: Selector): this;
nextUntil(selector: Selector, filter?: Selector): this;
prev(selector?: Selector): this;
prevAll(selector?: Selector): this;
prevUntil(selector: Selector, filter?: Selector): this;

Parameters

Returns

A new Dabby collection of sibling elements gathered in document order.

Examples

import $ from "dabbyjs";
import "dabbyjs/traversal/next-prev/next-prev";

// Highlight whatever directly follows the active item
$("li.active").next().addClass("up-next");
import $ from "dabbyjs";
import "dabbyjs/traversal/next-prev/next-prev";

// All paragraphs after a section heading, until the next heading
$("h2").nextUntil("h2", "p");
import $ from "dabbyjs";
import "dabbyjs/traversal/next-prev/next-prev";

// Every previous form group, regardless of selector
$(".form-group.error").prevAll(".form-group");

See also