Since you already loading JQuery, add the following $('document')
:
(function($) {
$(window).load(function() { //lets wait for all to be loaded
alert("Accordion script loaded");
var acc = document.getElementsByClassName("accordion");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function() {
this.classList.toggle("active");
var panel = this.nextElementSibling;
if (panel.style.maxHeight){
panel.style.maxHeight = null;
} else {
panel.style.maxHeight = panel.scrollHeight + "px";
}
}
}
});
})(jQuery);
looks like document.getElementsByClassName("accordion");
its returning NULL
and you are trying to set the style
property of it, this due to the script running too early, so nothing is found.