JavaScript Event Issue on Shopify Store

Topic summary

Issue: A click event on an existing element in a Shopify store is not triggering the expected JavaScript function.

Context: The original poster is more backend-focused and referenced their site (secondstartfinancial.com). A code block was included but contained no visible code, limiting diagnosis.

Latest input/suggestions:

  • Another participant notes the script will only run if the element with the specified ID actually exists at the time the code runs.
  • They advise placing the event-binding code after all scripts/HTML have loaded so the element is present (i.e., run after the DOM is ready).

Key technical point: Ensuring code runs after the DOM is loaded (e.g., after parsing completes) helps avoid attaching listeners to elements that aren’t yet in the document.

Status/outcome: No confirmed fix yet; the discussion remains open.

Open questions/action items:

  • Verify the correct element ID and timing of the script execution.
  • Share the actual code to enable targeted troubleshooting.
  • Confirm where the script is placed in the theme and whether the DOM-ready approach is used.
Summarized with AI on January 22. AI used: gpt-5.

Hi all,

I’m facing an issue with my Shopify store’s JavaScript. I’ve got this piece of code:


Despite the element existing, clicking it doesn’t trigger the expected function. Any thoughts?

For context, I run https://secondstartfinancial.com/ and am more familiar with backend processes.

1 Like

Hi @KaylaDavis

The following script only run if the element with ID, myElement exist. You also need to place this code after all script has been read