Skip to content

Instantly share code, notes, and snippets.

@wpflames
Created September 9, 2020 06:36
Show Gist options
  • Select an option

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

Select an option

Save wpflames/fe9e372b98e12af12596de81d14811cc to your computer and use it in GitHub Desktop.
JavaScript add class / remove class
const sizes = document.querySelectorAll('.size');
function changeSize(){
sizes.forEach(size => size.classList.remove('active'));
this.classList.add('active');
}
sizes.forEach(size => size.addEventListener('click', changeSize));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment