Skip to content

create a button dynamically use javascript behavior not correct when enable hx-boost. #3126

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

You must be logged in to vote

Oh right, htmx:load can be confusing because of its name, but as its documentation states:

This event is triggered when a new node is loaded into the DOM by htmx.

So for each node added by htmx in the DOM, including during the page's lifetime, your function would execute and instanciate a new button.
If you want to run this logic only on the first page load or when the body content changes (i.e. a boosted request that replaces the page content and acts as if you changed page), I think you could check if the event.detail.elt is the body itself or not (if it isn't, ignore it)

It seems you're not using any htmx feature in your JS code though, so you might even want to consider not relying …

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@zw963
Comment options

@zw963
Comment options

@zw963
Comment options

@Telroshan
Comment options

Answer selected by zw963
@zw963
Comment options

@zw963
Comment options

@Telroshan
Comment options

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