Skip to content

<script> tags behave differently in htmx 1.5 and htmx 1.6.1 #723

Answered by 1cg
formoxyz asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, script tags are now evaluated the "normal" way, that is the way that they would be interpreted if you have them in a regular web page, so variables at the top level will be global.

To deal with this you need to introduce a new scope, for example by wrapping everything in a function:

  (function(){
    //***** The line below gives error when more than one component is in the page ******//
    let fdz = document.getElementById("fdz_<%= @block.id %>")
    //More code implementing dropzone js
   )()

This wraps all the code in a function and then invokes the function, shielding the top level scope from your variables.

Replies: 1 comment 1 reply

Comment options

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

Answer selected by 1cg
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