Created
February 14, 2023 12:36
-
-
Save diggeddy/d748c6833ab9be7333af2a3a4d1fd60a to your computer and use it in GitHub Desktop.
vanilla JS simple toggle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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