Accordion only open for a few seconds before taking me to top of page!

I’m new to javascript and have just worked out how to make an accordion on an HTML page on our company website. The accordion is displaying correctly on the page, however when you click to open it, it stays open for a few seconds and then automatically takes you to the top of the page and away from the accordion. I don’t know what I’ve done, this is the code that I’ve put onto the page for the accordion:

var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
  acc[i].onclick = function() {
    var panel = this.nextElementSibling;
    if ({ = null;
    } else { = panel.scrollHeight + "px";

Please help!

Thank you :rofl: