+ 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
7 Antworten
+ 4
https://code.sololearn.com/WZutdnBi698E/?ref=app
+ 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;
});
});
}
+ 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 ;)
+ 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 ^^
+ 2
visph thanks i know get it..
+ 2
visph thanks bro. know it works with the right color background...
+ 1
visph thanks bro..