Support » Plugin: Scripts n Styles » Javascript Not Working

  • 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 to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author WraithKenny

    (@wraithkenny)

    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.