Skip to content

Instantly share code, notes, and snippets.

@diggeddy
Created February 14, 2023 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diggeddy/d748c6833ab9be7333af2a3a4d1fd60a to your computer and use it in GitHub Desktop.
Save diggeddy/d748c6833ab9be7333af2a3a4d1fd60a to your computer and use it in GitHub Desktop.
vanilla JS simple toggle
const elements = document.querySelectorAll('.className');
elements.forEach(element => {
element.addEventListener('click', () => {
elements.forEach(sibling => sibling.classList.remove('active'));
element.classList.toggle('active');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment