Archived topic
JS Script injected but not working...
3 replies · Started by Sally on October 26, 2022
Hello,
I wanted to add an accordion to my site without adding a bulky plugin and so used https://www.w3schools.com/howto/howto_js_accordion.asp to help me and used a hook to inject the JS onto the page in question.
Their directions use an HTML button, GP already has it's HTML button so I just overrode the styling for the class 'accordion' but the script that actually gets the accordion to open and close didn't work.
So, I tested just using a 'div' instead of a button, as neither the script nor the styling mention the button and only the classes. But, I'm no further along. If I check the page source the script is there and the script works fine in the W3 sandbox just doesn't appear to work on my site.
The page in question is https://www.seoinmotion.com/services-local-seo-consultant/
Fixed - I was reading up on issues with JS not working on WP and a few people recommended adding the script just before the closing body tag. So I updated the location to after content via hook and it's working now :)
Hi Sally,
Please check out this too - Create Accordion "block" with GenerateBlocks
- https://www.youtube.com/watch?v=s9NN1zDus2w
You may be interested in this as an alternative solution.
Glad to hear you got that working Sally!!