Skip to content

prevAll(), closest() and other traversals don't return results in jQuery's order #117

Closed

Description

@gravitypdf-bot

Follow-up from #72. Assumes #72 is merged.

Problem

jQuery returns the results of its reverse-direction traversals in reverse document order, de-duplicated (.parents(), .parentsUntil(), .prevAll(), .prevUntil()), and runs uniqueSort on the others. #72 brought parents() and parentsUntil() in line, but the rest still return results grouped by starting element, in walk order:

$xml = '<r><a/><b/><c/><d/></r>';

qp($xml, 'c, d')->prevAll();
// QueryPath: b, a, c, b, a  → after de-dup: b, a, c   (grouped per start node)
// jQuery:    c, b, a                                  (reverse document order)

This matters beyond presentation: since #70, positional selectors (:first, :eq(n), …) count within the set, so prevAll(':first') picks a different element depending on the method's ordering. The CHANGELOG's "position within the set" guarantee currently holds only for some methods.

Affected

prevAll(), prevUntil(), closest(), parent(), siblings(), next()/prev() on multi-element sets. Each needs checking against jQuery 3.x.

Proposal

Decide the order per method from jQuery's source, and apply it in one place (ideally the shared traversal helper from the consolidation issue) rather than per method. This is a behaviour change and should be marked as one in the CHANGELOG.

Activity

  1. added 2 commits that reference this issue on Oct 26, 2026
    3763888
    91f0a89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions