portalzine

portalzine / HTMX - Process on DOM changes

Last active 3 months ago

Like 0

portalzine revised this gist 1 year ago · 208ee0a

1 file changed, 10 insertions

htmx-mutationobserver.js (file created)
@@ -0,0 +1,10 @@
1 + const observer = new MutationObserver((mutations) => {
2 + mutations.forEach((mutation) => {
3 + mutation.addedNodes.forEach((node) => {
4 + if (node.nodeType === 1 && !node["htmx-internal-data"]) {
5 + htmx.process(node)
6 + }
7 + })
8 + })
9 + })
10 + observer.observe(document, {childList: true, subtree: true})