Any way to do DOM manipulation with JS on an HTML snippet?

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? 
    Zoho Desk Resources

    • Desk Community Learning Series


    • Digest


    • Functions


    • Meetups


    • Kbase


    • Resources


    • Glossary


    • Desk Marketplace


    • MVP Corner


    • Word of the Day


      Zoho CRM Plus Resources

        Zoho Books Resources


          Zoho Subscriptions Resources

            Zoho Projects Resources


              Zoho Sprints Resources


                Zoho Orchestly Resources


                  Zoho Creator Resources


                    Zoho WorkDrive Resources



                      Zoho Campaigns Resources

                        Zoho CRM Resources

                        • CRM Community Learning Series

                          CRM Community Learning Series


                        • Tips

                          Tips

                        • Functions

                          Functions

                        • Meetups

                          Meetups

                        • Kbase

                          Kbase

                        • Resources

                          Resources

                        • Digest

                          Digest

                        • CRM Marketplace

                          CRM Marketplace

                        • MVP Corner

                          MVP Corner




                          Zoho Writer Writer

                          Get Started. Write Away!

                          Writer is a powerful online word processor, designed for collaborative work.

                            Zoho CRM コンテンツ




                              ご検討中の方