Any way to do DOM manipulation with JS on an HTML snippet?
I want to use JavaScript to set event listeners on some elements produced in by HTML snippet written in Deluge. I tried creating a nodeJs function and calling it at the end of the HTML snippet, but when the code runs, I get an error saying the document is undefined. Thinking that perhaps the issue was just that the JavaScript was trying to access the DOM before it was fully rendered, I tried throwing a setTimeout in there to make sure the DOM got a chance to load. That prevented the "document is undefined" error, but the code still doesn't work. I also tried throwing the code in a widget, but the widget is not allowed access to the DOM outside the Iframe where it lives.
When I copy and paste my code into the console, it has the exact expected behavior. I just need to integrate this into the actual page. Any ideas?