Title: Javascript Not Working
Last modified: December 5, 2018

---

# Javascript Not Working

 *  [cooksara17](https://wordpress.org/support/users/cooksara17/)
 * (@cooksara17)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/javascript-not-working-26/)
 * I’m an amateur when it comes to this, so I’m having trouble understanding how
   to patch this issue.
 * I have this JS code:
 *     ```
       var acc = document.getElementsByClassName("accordion");
       var i;
   
       for (i = 0; i < acc.length; i++) {
           acc[i].addEventListener("click", function() {
               this.classList.toggle("active");
           var panel = this.nextElementSibling;
           if (panel.style.display === "block") {
               panel.style.display = "none";
           } else {
               panel.style.display = "block";
           }
       });
       }
       ```
   
 * Which I have been trying to add to an individual page using the Scripts & Styles
   Plug In. It does not work at all. (The buttons do nothing upon click). I have
   tried other, very simple strings, to test. No JS appears to work.
 * I’ve tried adding a document ready string within the page, no success. I have
   also tried making sure jquery is enqueued by using the jquery enqueue option 
   on the scripts & styles home plug in page.
 * My concern is that all the scripts involved with the theme we have are causing
   this upset. Please advise.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fjavascript-not-working-26%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [WraithKenny](https://wordpress.org/support/users/wraithkenny/)
 * (@wraithkenny)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/javascript-not-working-26/#post-10959523)
 * I have a feeling that you added the code to the “head” section, which means the
   elements aren’t yet created when the code runs. Try moving it to the footer (
   the second box).

Viewing 1 replies (of 1 total)

The topic ‘Javascript Not Working’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/scripts-n-styles_46515d.svg)
 * [Scripts n Styles](https://wordpress.org/plugins/scripts-n-styles/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/scripts-n-styles/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/scripts-n-styles/)
 * [Active Topics](https://wordpress.org/support/plugin/scripts-n-styles/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/scripts-n-styles/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/scripts-n-styles/reviews/)

## Tags

 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [jquery](https://wordpress.org/support/topic-tag/jquery/)

 * 1 reply
 * 2 participants
 * Last reply from: [WraithKenny](https://wordpress.org/support/users/wraithkenny/)
 * Last activity: [7 years, 6 months ago](https://wordpress.org/support/topic/javascript-not-working-26/#post-10959523)
 * Status: not a support question