+ 3

i want the previous clicked div element background to go off when the next current div element is given a background ..

I have four div elements for which each element is given a background color when it is clicked. #code:https://code.sololearn.com/Wl43dQsEVgxD/?ref=app

10th Jun 2021, 9:04 PM
🤖Web Gig🤖
🤖Web Gig🤖 - avatar
7 Réponses
+ 4
https://code.sololearn.com/WZutdnBi698E/?ref=app
10th Jun 2021, 9:27 PM
visph
visph - avatar
+ 2
window.onload=()=>{ const items=document.querySelectorAll(".item"); let last = null; items.forEach(item =>{ item.addEventListener("click",()=>{ item.classList.toggle("background"); if (last) last.classList.toggle("background"); last = item; }); }); }
10th Jun 2021, 9:14 PM
visph
visph - avatar
+ 2
however, rgba colors in hex format are not well supported by all brothers ^^ since you give full alpha chanel (FF), better to use only rgb hex... if you need alpha chanel, better to use rgba() notation ;)
10th Jun 2021, 9:17 PM
visph
visph - avatar
+ 2
my code works ^^ did you have color displayed on click before? because as I said in my second post hex colors with 8 digits are not working in all brothers: on my phone, I must remove the 2 last digits of color to let it works ^^
10th Jun 2021, 9:25 PM
visph
visph - avatar
+ 2
visph thanks i know get it..
10th Jun 2021, 9:28 PM
🤖Web Gig🤖
🤖Web Gig🤖 - avatar
+ 2
visph thanks bro. know it works with the right color background...
10th Jun 2021, 9:41 PM
🤖Web Gig🤖
🤖Web Gig🤖 - avatar
+ 1
visph thanks bro..
10th Jun 2021, 9:18 PM
🤖Web Gig🤖
🤖Web Gig🤖 - avatar