diff options
author | Vincent <vichenzo-thebaud@hotmail.com> | 2023-10-07 06:25:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-06 22:25:03 -0600 |
commit | 7274454360aa5ff5f9a5ed1657450b93e9529b89 (patch) | |
tree | 908305e18507216048e47ec45dd915dbd79dba81 /src/htmx.js | |
parent | 4f63581c55828a807aee3a9a2e501d482aa8f351 (diff) | |
download | htmx-7274454360aa5ff5f9a5ed1657450b93e9529b89.tar.gz htmx-7274454360aa5ff5f9a5ed1657450b93e9529b89.zip |
[New feature] selector-less next and previous targets (#1478)
* nextElementSibling and previousElementSibling target selectors
* Renamed nextElementSibling => next, previousElementSibling => previous
Diffstat (limited to 'src/htmx.js')
-rw-r--r-- | src/htmx.js | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/htmx.js b/src/htmx.js index 1e544690..e6cd3892 100644 --- a/src/htmx.js +++ b/src/htmx.js @@ -596,8 +596,12 @@ return (function () { return [closest(elt, normalizeSelector(selector.substr(8)))]; } else if (selector.indexOf("find ") === 0) { return [find(elt, normalizeSelector(selector.substr(5)))]; + } else if (selector === "next") { + return [elt.nextElementSibling] } else if (selector.indexOf("next ") === 0) { return [scanForwardQuery(elt, normalizeSelector(selector.substr(5)))]; + } else if (selector === "previous") { + return [elt.previousElementSibling] } else if (selector.indexOf("previous ") === 0) { return [scanBackwardsQuery(elt, normalizeSelector(selector.substr(9)))]; } else if (selector === 'document') { @@ -1279,12 +1283,14 @@ return (function () { var from_arg = consumeUntil(tokens, WHITESPACE_OR_COMMA); if (from_arg === "closest" || from_arg === "find" || from_arg === "next" || from_arg === "previous") { tokens.shift(); - from_arg += - " " + - consumeUntil( - tokens, - WHITESPACE_OR_COMMA - ); + var selector = consumeUntil( + tokens, + WHITESPACE_OR_COMMA + ) + // `next` and `previous` allow a selector-less syntax + if (selector.length > 0) { + from_arg += " " + selector; + } } triggerSpec.from = from_arg; } else if (token === "target" && tokens[0] === ":") { |