Skip to content

Instantly share code, notes, and snippets.

@wpflames
Created April 11, 2022 10:24
Show Gist options
  • Select an option

  • Save wpflames/a0f4197060a31e4500f1779ae98af7c2 to your computer and use it in GitHub Desktop.

Select an option

Save wpflames/a0f4197060a31e4500f1779ae98af7c2 to your computer and use it in GitHub Desktop.
Accordion with Vanilla JS
const accTitle = document.getElementsByClassName("accordion-title");
let i;
for (i = 0; i < accTitle.length; i++) {
accTitle[i].addEventListener("click", function() {
this.classList.toggle("active");
let panel = this.nextElementSibling;
panel.classList.toggle("active");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment