Skip to content

Button's 2nd click shows targetError #1631

Answered by Telroshan
taylorren asked this question in Q&A
Discussion options

You must be logged in to vote

You specify hx-swap="outerHTML", which replaces your whole div.

This means that after the request, <div id="div1">(Blank)</div> won't be part of the DOM anymore and got replaced by the response content of the request.
Thus, subsequent clicks on the button don't work because htmx cannot find an element with the id div1 in the document anymore.

If you wish to keep the div1, you might want to use hx-swap="innerHTML" instead, so that only its inner content gets swapped, and the div itself remains

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@taylorren
Comment options

Answer selected by taylorren
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants