mysterious-toddler-20573
10/16/2021, 7:50 PMmysterious-toddler-20573
10/16/2021, 7:55 PMmysterious-toddler-20573
10/16/2021, 7:56 PMgorgeous-airport-54386
10/16/2021, 8:06 PMmysterious-toddler-20573
10/16/2021, 8:06 PMmysterious-toddler-20573
10/16/2021, 8:07 PMgorgeous-airport-54386
10/16/2021, 8:07 PMmysterious-toddler-20573
10/16/2021, 8:08 PMgorgeous-ghost-95789
10/16/2021, 8:10 PMgorgeous-ghost-95789
10/16/2021, 8:18 PMgorgeous-airport-54386
10/16/2021, 8:19 PMincalculable-pager-33872
10/16/2021, 8:47 PMcolossal-glass-79762
10/16/2021, 8:59 PMmysterious-toddler-20573
10/16/2021, 9:41 PMgreat-computer-55422
10/17/2021, 3:00 AMsalmon-xylophone-28580
10/17/2021, 8:08 AMsalmon-xylophone-28580
10/17/2021, 11:59 AMmysterious-toddler-20573
10/17/2021, 1:25 PMmysterious-toddler-20573
10/17/2021, 1:25 PMgentle-notebook-11755
10/17/2021, 3:19 PMmysterious-toddler-20573
10/17/2021, 3:22 PMhtmx.onLoad() function: https://htmx.org/docs/#3rd-partymysterious-toddler-20573
10/17/2021, 3:23 PMjs
htmx.onLoad(function(content) {
var clickables = content.querySelectorAll(".whatever");
// initialize clickables...
})mysterious-toddler-20573
10/17/2021, 3:24 PMmysterious-toddler-20573
10/17/2021, 3:25 PMjs
let myDiv = document.getElementById('my-div')
fetch('http://example.com/movies.json')
.then(response => response.text())
.then(data => { myDiv.innerHTML = data; htmx.process(myDiv); } );gentle-notebook-11755
10/17/2021, 3:37 PMmysterious-toddler-20573
10/17/2021, 4:03 PMgentle-notebook-11755
10/17/2021, 4:35 PM<script>
const mainUX = new Main();
console.log(mainUX); // logs the class object
</script>
What helped me was your mention of the htmx.onLoad() method. It made me realize I was missing a general instantiation of the class that could be available everywhere.
So, in the htmx loaded partials, I can now invoke methods of the class like this mainUX.sayHi() and it produces the expected results.
Now, is this too hacky? Is it there a more standard way to do this?late-king-98305
10/18/2021, 1:36 PMtall-cat-32859
10/18/2021, 3:16 PMabundant-planet-84751
10/18/2021, 6:25 PM