I was basically implementing this from W3School: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_accordion_symbol
I tried making the javascript into a separate file called accordion.js
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";
}
}
}
and tried calling the javascript file via HTML doing this:
<script type="text/javascript" src="accordion.js"></script>
Can anyone tell me what I can do to fix this and help explain why it didn't work?