Avatar of Hobert Cruz
Hobert Cruz

asked on 

Convert addEventListener to real function..

Hi experts, how to convert the code below into real function? I need to convert the code from addEventListener to real function like, function doit(){}.  Thank you!

  var acc = document.getElementsByClassName("accordion");
  var i;
  for (i = 0; i < acc.length; i++) {
    acc[i].addEventListener("click", function(){
      var panel = this.nextElementSibling;
      if (panel.style.display === "block") {
        panel.style.display = "none";
      } else {
        panel.style.display = "block";

Open in new window


Avatar of undefined
Last Comment
Michel Plungjan

8/22/2022 - Mon