From f45bff61f253be71a426272c27f36a13b6111149 Mon Sep 17 00:00:00 2001 From: Ahete007 <35165131+Ahete007@users.noreply.github.com> Date: Thu, 3 Dec 2020 22:18:43 +0530 Subject: [PATCH] Update script.js we can use toggle here instead of calling a separate function for removing the class. --- expanding-cards/script.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/expanding-cards/script.js b/expanding-cards/script.js index 68d6b5c..f44cfb2 100644 --- a/expanding-cards/script.js +++ b/expanding-cards/script.js @@ -1,14 +1,9 @@ -const panels = document.querySelectorAll('.panel') +const panels=document.querySelectorAll('.panel') +panels.forEach(panel=>{ -panels.forEach(panel => { - panel.addEventListener('click', () => { - removeActiveClasses() - panel.classList.add('active') + panel.addEventListener('click',()=>{ + + panel.classList.toggle('active') }) }) -function removeActiveClasses() { - panels.forEach(panel => { - panel.classList.remove('active') - }) -} \ No newline at end of file