#4077·htmx

[htmx4] `q('.el').q('next .el')` either wrongly scopes the query, or documentation is a bit misleading

Author: adamkissCreated Sep 15, 2026Updated Sep 16, 2026

In https://four.htmx.org/extensions/hx-live#q, this is in examples:

// selectors
q('next .foo')                  // first match after this element
q('previous .foo')              // closest match before this element
// chaining
q('.row').q('next .row')          // each row's successor

Given this, I would expect following work:

q('#parent .el.selected').q('previous .el')
q('#parent .el.selected').q('next .el')

But it doesn't, because previous/next don't change the root of the searching qsa call, but search inside .el.selected itself. To properly get next/prev, we also need to scope the calls:

q('#parent .el.selected').q('previous .el in #parent')
q('#parent .el.selected').q('next .el in #parent')

I am not sure if this is a bug, misleading documentation or simply reading comprehension error.