Skip to content

previous <CSSselector> and next <CSSselector> find more than just siblings. Improve docs? #3430

@JanRomero

Description

@JanRomero

Hi,

hx-target="previous" works like Element.previousElementSibling(). If the element is its parent’s sole child, no target will be found.

However, hx-target="previous <CSS selector>" will apparently find anything on any hierarchy level, as long as it begins and ends before the source element.

Here is a fiddle showing what I mean: https://jsfiddle.net/cuokm8gz/2/

I like this, but the docs state “previous .error will target the closest previous sibling with error class”.

I propose that previous <CSS selector> should either be restricted to siblings (😩) or the docs should be changed to “element” instead of “sibling”. If the latter is chosen, additional tests for next and previous should be added to prevent a regression on this. I will gladly start a PR for this.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions